Created
May 28, 2020 16:28
-
-
Save ZhouYang1993/00425994628744547c37edf0c060f94e 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
| my_list = [1, 2, 3, 4, 5] | |
| print(my_list) | |
| # [1, 2, 3, 4, 5] | |
| my_list_iterator = iter(my_list) | |
| print(my_list_iterator) | |
| # <list_iterator object at 0x7f048a4b67f0> | |
| next(my_list_iterator) | |
| # 1 | |
| next(my_list_iterator) | |
| # 2 | |
| next(my_list_iterator) | |
| # 3 | |
| next(my_list) | |
| # TypeError: 'list' object is not an iterator |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment