10.14. Iterator Repeat

  • Lazy evaluated

  • itertools.repeat(object[, times])

>>> from itertools import repeat
>>>
>>>
>>> data = repeat('Beetlejuice', times=3)
>>>
>>> next(data)
'Beetlejuice'
>>>
>>> next(data)
'Beetlejuice'
>>>
>>> next(data)
'Beetlejuice'
>>>
>>> next(data)
Traceback (most recent call last):
StopIteration

10.14.1. Use Case - 1

>>> for string in repeat('hello', times=3):
...     print(string)
...
hello
hello
hello