Last active
September 6, 2020 04:46
-
-
Save astellon/8374e31635224b7cef85b5adb5e8f852 to your computer and use it in GitHub Desktop.
`cycle` is a function to make an iterator an infinitely circular generator
This file contains 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 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