Skip to content

Instantly share code, notes, and snippets.

@astellon
Last active September 6, 2020 04:46
Show Gist options
  • Save astellon/8374e31635224b7cef85b5adb5e8f852 to your computer and use it in GitHub Desktop.
Save astellon/8374e31635224b7cef85b5adb5e8f852 to your computer and use it in GitHub Desktop.
`cycle` is a function to make an iterator an infinitely circular generator
def cycle(iterable):
it = iter(iterable)
while True:
try:
yield next(it)
except StopIteration:
it = iter(iterable)
continue
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment