Created
November 17, 2014 10:03
-
-
Save ramalho/f587480daca3c7b39786 to your computer and use it in GitHub Desktop.
Using *my_iterable when calling a function forces the Python interpreter to eagerly iterate over my_iterable
This file contains hidden or 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 prange(n): | |
| ... for i in range(n): | |
| ... print('->', i) | |
| ... yield i | |
| ... | |
| >>> def f(a, b, c): | |
| ... print((a, b, c)) | |
| ... | |
| >>> f(*prange(3)) | |
| -> 0 | |
| -> 1 | |
| -> 2 | |
| (0, 1, 2) | |
| >>> def g(*args): | |
| ... print(args) | |
| ... | |
| >>> g(*prange(3)) | |
| -> 0 | |
| -> 1 | |
| -> 2 | |
| (0, 1, 2) | |
| >>> |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment