Skip to content

Instantly share code, notes, and snippets.

Embed
What would you like to do?
when generators share their state
"""
This program generates the following table:
01 02 03 04 05 06 07 08 09 0A 0B 0C 0D 0E 0F
It shows what happens when two generators share the same state.
Contrast with: https://gist.github.com/3814556
"""
def each( seq ):
"""
This does exactly what the built-in iter() function does.
iter() is also invoked by the 'for' loop itself, so it's
doubly redundant.
"""
for e in seq: yield e
gen = each('0123456789ABCDEF')
for y in gen:
for x in gen:
print ( y + x ),
print
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
You can’t perform that action at this time.