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

Ansible - ERROR! the field 'hosts' is required but was not set -

customize file_field button ruby on rails -

SoapUI on windows 10 - high DPI/4K scaling issue -