ID EN
Itertools

repeat

Python 3.11

Make an iterator that returns object over and over again. Runs indefinitely unless the times argument is specified.

Syntax

PYTHON
itertools.repeat(object[, times])

Examples

Example 1
PYTHON
def repeat(object, times=None):
     repeat(10, 3) --> 10 10 10
    if times is None:
        while True:
            yield object
    else:
        for i in range(times):
            yield object
Example 2
PYTHON
>>> list(map(pow, range(10), repeat(2)))
[0, 1, 4, 9, 16, 25, 36, 49, 64, 81]