If you use a generator instead of a string then you'll only loop once and wait forever.
On Wed, Jan 19, 2022 at 11:49 AM jerome via code-quality < email@example.com> wrote:
Hi everyone, first I'm not quite sure if this is the right place to make this kind of suggestion/ask question but, `itertools.cycle` makes a copy of the iterable its given and as the note says: this may require significant auxiliary storage. Maybe I don't see the reason why this is nescessary but, shouldn't this work just as well:
def cycle(iterable): # cycle('ABCD') --> A B C D A B C D A B C D ... while iterable: for element in iterable: yield element
Instead of the current:
def cycle(iterable): # cycle('ABCD') --> A B C D A B C D A B C D ... saved =  for element in iterable: yield element saved.append(element) while saved: for element in saved: yield element
code-quality mailing list -- firstname.lastname@example.org To unsubscribe send an email to email@example.com https://mail.python.org/mailman3/lists/code-quality.python.org/ Member address: firstname.lastname@example.org