Skip to content

Instantly share code, notes, and snippets.

@edenau
Last active December 27, 2019 16:37
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 edenau/d23b71ff473720ae19fd4514f2232bdb to your computer and use it in GitHub Desktop.
Save edenau/d23b71ff473720ae19fd4514f2232bdb to your computer and use it in GitHub Desktop.
Python Generator
def gen(n): # an infinite sequence generator that generates integers >= n
while True:
yield n
n += 1
G = gen(3) # starts at 3
print(next(G)) # 3
print(next(G)) # 4
print(next(G)) # 5
print(next(G)) # 6
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment