On this page
  1. itertools.repeat
  2. Import
  3. Signature & Overview
  4. Usage
  5. Gotchas
  6. REPL Inspect

itertools.repeat

Prev: itertools.product | Up: itertools | Next: itertools.starmap
Rel: itertools.accumulate, itertools.batched, itertools.chain, itertools.combinations
Ref: docs.python.org — itertools.repeat
Tags: #public #python3 #stdlib #itertools


Import

import itertools
from itertools import repeat

Signature & Overview

itertools.repeat(object [,times]) -> create an iterator which returns the object

for the specified number of times. If not specified, returns the object endlessly.

Usage

from itertools import repeat

assert list(repeat("x", 3)) == ["x", "x", "x"]
# Supply a constant argument to map()
assert list(map(pow, [2, 3, 4], repeat(2))) == [4, 9, 16]

Gotchas

REPL Inspect

from itertools import repeat
help(repeat)

Linked from

Related notes