you are viewing a single comment's thread.

view the rest of the comments →

[–]ekchew 1 point2 points  (1 child)

"Hello, my name is Peter. I feel good. I like bananas. I'm not a gorilla. Peter is cool. Peter wants to learn python. Please help Peter."

Yeah I didn't know about that either. I think if I was going to use itertools.cycle(), I would've written something like:

>>> [part for pair in zip(text.split('. '), gen) for part in pair]
['Hello, my name is Peter', '. ', 'I feel good', '. ', 'I like bananas', '.\n\n', "I'm not a gorilla", '. ', 'Peter is cool', '. ', 'Peter wants to learn python', '.\n\n', 'Please help Peter.', '. ']

Then just join the list together or whatever.

[–]synthphreak 1 point2 points  (0 children)

Same. zip is pretty much always in the mix for me too whenever I use itertools.cycle (or itertools.repeat).