Skip to content

Instantly share code, notes, and snippets.

@ashwin
Created May 3, 2012 22:27
Show Gist options
  • Star 0 You must be signed in to star a gist
  • Fork 0 You must be signed in to fork a gist
  • Save ashwin/2590010 to your computer and use it in GitHub Desktop.
Save ashwin/2590010 to your computer and use it in GitHub Desktop.
Generator function in Python
# Infinite sequence generator
def sequenceGen():
i = 0
while True:
yield i
i += 1
g = sequenceGen()
print( next( g ) ) # 0
print( next( g ) ) # 1
print( next( g ) ) # 2
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment