Created
July 31, 2020 13:21
-
-
Save kshirsagarsiddharth/8183d986705df596980bc329cf962dd1 to your computer and use it in GitHub Desktop.
yield from
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
| def cities(): | |
| for city in ['Delhi','Mumbai','Pune','Hyderabad']: | |
| yield city | |
| def squares(): | |
| for val in range(10): | |
| yield val ** 2 | |
| def all_in_one(): | |
| for city in cities(): | |
| yield city | |
| for number in squares(): | |
| yield number | |
| def generator_splitted(): | |
| yield from cities() | |
| yield from squares() | |
| list(all_in_one()) == list(generator_splitted()) # True |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment