Created
May 28, 2020 21:35
-
-
Save ZhouYang1993/f5d63fd3d60a831a1a45daf335604daf to your computer and use it in GitHub Desktop.
Iterators in Python
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
| # convert an Iterable to an Iterator | |
| my_list_iterator = iter(my_list) | |
| while True: | |
| try: | |
| # get the next item | |
| element = next(my_list_iterator) | |
| except StopIteration: | |
| # if StopIteration is raised, stop for loop | |
| break |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment