Created
July 25, 2012 16:14
-
-
Save sonkm3/3177018 to your computer and use it in GitHub Desktop.
python generator
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 temp(): | |
... print 'called' | |
... for lp in [1,2,3,4,5]: | |
... print 'called:' + str(lp) | |
... yield lp | |
... | |
>>> gen = temp() | |
>>> for index in gen: | |
... pass | |
... | |
called | |
called:1 | |
called:2 | |
called:3 | |
called:4 | |
called:5 | |
>>> |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment