Skip to content

Instantly share code, notes, and snippets.

@ramalho
Created November 17, 2014 10:03
Show Gist options
  • Select an option

  • Save ramalho/f587480daca3c7b39786 to your computer and use it in GitHub Desktop.

Select an option

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
>>> 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