Last active
March 19, 2017 05:26
-
-
Save jaantollander/eaf8a4fe2beb40744a017d1bdaf46e86 to your computer and use it in GitHub Desktop.
Example of python yield from aka generator delegation syntax
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
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