Skip to content

Instantly share code, notes, and snippets.

@jrjames83
Created January 23, 2017 18:00
Show Gist options
  • Save jrjames83/4a2ad36ab3b598d1ce1a7962b0a89bac to your computer and use it in GitHub Desktop.
Save jrjames83/4a2ad36ab3b598d1ce1a7962b0a89bac to your computer and use it in GitHub Desktop.
# Multiple yield statements
def gen_up_to(limit):
n = 0
while n <= limit:
if n % 2 <= 0:
yield (n, "even")
if n % 2 > 0:
yield (n, "odd")
n += 1
yield 'All Done'
it = gen_up_to(10)
for val in it:
print (it.__next__())
""" Where are the even ones?
(1, 'odd')
(3, 'odd')
(5, 'odd')
(7, 'odd')
(9, 'odd')
All Done
"""
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment