Created
February 12, 2016 21:05
-
-
Save ehermes/c6b86b4ef9b6c5ff2ee4 to your computer and use it in GitHub Desktop.
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
| def make_incrementors(start, amounts): | |
| y = [start] | |
| results = [] | |
| for x in amounts: | |
| def add_x(): | |
| y[0] += x | |
| return y[0] | |
| results.append(add_x) | |
| return results | |
| incrementors = make_incrementors(7, [1, 2, 3, 4, 5]) | |
| print(incrementors) | |
| print(incrementors[0]()) | |
| print(incrementors[1]()) | |
| print(incrementors[2]()) |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment