Last active
October 17, 2016 06:38
-
-
Save yuttie/41d5616b7c7d52979cd4ecc256bac430 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_counter(init): | |
| count = [init] | |
| def f(): | |
| count[0] += 1 | |
| return count[0] - 1 | |
| return f | |
| c = make_counter(0) | |
| c() |
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_counter(init): | |
| count = init | |
| def f(): | |
| nonlocal count | |
| count += 1 | |
| return count - 1 | |
| return f | |
| c = make_counter(0) | |
| c() |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment