python - itertools.repeat VS itertools.cycle -


is there difference between itertools.repeat(n) , itertools.cycle(n)? seems, produce same output. 1 more efficient use in situation need infinite loop of element?

simply, itertools.repeat repeat given argument, , itertools.cycle cycle on given argument. don't run code, example:

from itertools import repeat, cycle  in repeat('abcd'): print(i) # abcd, abcd, abcd, abcd, ...  in cycle('abcd'): print(i) # a, b, c, d, a, b, c, d, ... 

Comments

Popular posts from this blog

c++ - list<myClass<int> * > sort -

c - Defining floating point constants, how many digits are useful? -

C# Apple Bonjour - how to monitor service records within Windows -