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
Post a Comment