Skip to content

Instantly share code, notes, and snippets.

@felixhummel
Created March 1, 2024 13:27
Show Gist options
  • Save felixhummel/80e03633f914296401e6813c3e4be44f to your computer and use it in GitHub Desktop.
Save felixhummel/80e03633f914296401e6813c3e4be44f to your computer and use it in GitHub Desktop.
iter stuff
>>> def iter_stuff():
... yield 1
... yield 2
... yield 4
...
>>> next(iter_stuff())
1
>>> next(iter_stuff())
1
>>> next(iter_stuff())
1
>>> next(iter_stuff())
1
>>> my_iter = iter_stuff()
>>> next(my_iter)
1
>>> next(my_iter)
2
>>> next(my_iter)
4
>>> next(my_iter)
Traceback (most recent call last):
Cell In[11], line 1
next(my_iter)
StopIteration
>>> [i for i in iter_stuff()]
[1, 2, 4]
>>> list(iter_stuff())
[1, 2, 4]
>>>
>>> consume_me = iter_stuff()
>>> list(consume_me)
[1, 2, 4]
>>> list(consume_me)
[]
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment