Skip to content

Instantly share code, notes, and snippets.

@blacksmithop
Created August 10, 2022 11:54
Show Gist options
  • Save blacksmithop/86f428333107fda6f8f382d3dd2c8bdd to your computer and use it in GitHub Desktop.
Save blacksmithop/86f428333107fda6f8f382d3dd2c8bdd to your computer and use it in GitHub Desktop.
Infinite iterator
from itertools import chain
def gen_iterables():
while True:
for i in range(1, 6): # memory equivalent to that used by `range` is consumed at any moment
yield range(i)
gen = chain.from_iterable(gen_iterables())
for i in range(20):
print(next(gen))
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment