Skip to content

Instantly share code, notes, and snippets.

@kshirsagarsiddharth
Created July 31, 2020 13:21
Show Gist options
  • Select an option

  • Save kshirsagarsiddharth/8183d986705df596980bc329cf962dd1 to your computer and use it in GitHub Desktop.

Select an option

Save kshirsagarsiddharth/8183d986705df596980bc329cf962dd1 to your computer and use it in GitHub Desktop.
yield from
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