Skip to content

Instantly share code, notes, and snippets.

@jaantollander
Last active March 19, 2017 05:26
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 jaantollander/eaf8a4fe2beb40744a017d1bdaf46e86 to your computer and use it in GitHub Desktop.
Save jaantollander/eaf8a4fe2beb40744a017d1bdaf46e86 to your computer and use it in GitHub Desktop.
Example of python yield from aka generator delegation syntax
def generator(): return range(10)
# Here f and g does the exactly same thing
# Generator delegation
def f():
yield from generator()
# Legacy python syntax
def g():
for i in generator():
yield i
# Test
assert list(f()) == list(g())
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment