Last active
July 19, 2019 08:06
-
-
Save eyaltrabelsi/c70929bf7b75c24bd9b16dfb2d1d9230 to your computer and use it in GitHub Desktop.
Python-tricks generator comprehension
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
# A generator comprehension is the lazy version of a list comprehension. | |
>>> m = (x ** 2 for x in range(5)) | |
>>> m | |
<generator object <genexpr> at 0x108efe408> | |
>>> list(m) | |
[0, 1, 4, 9, 16] | |
>>> m = (x ** 2 for x in range(5)) | |
>>> next(m) | |
0 | |
>>> list(m) | |
[1, 4, 9, 16] |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
maybe use
next(m)
to show what generators are? of a function yielding the results?