Created
March 1, 2024 13:27
-
-
Save felixhummel/80e03633f914296401e6813c3e4be44f to your computer and use it in GitHub Desktop.
iter stuff
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 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