Created
July 28, 2012 02:59
-
-
Save sonkm3/3191527 to your computer and use it in GitHub Desktop.
python generator by closure (count passed via list)
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 get_counter(): | |
| print 'get_counter' | |
| def counter(): | |
| count[0] = count[0] + 1 | |
| return count[0] | |
| count = [0] | |
| return counter | |
| counter = get_counter() | |
| for lp in range(5): | |
| print counter() |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment