CKTIS / Python
itertools.repeat
Devuelve el mismo objeto en cada lectura.
Versión: Python 3.14; repository image, production runtime not attested
Sintaxis
itertools.repeat(object[, times])Devuelve el mismo objeto en cada lectura.
Tres repeticiones del texto x dan tres posiciones y cero no da ninguna. Omitir times repite indefinidamente.
Para una lista todas las posiciones referencian el mismo objeto y ven sus cambios.
import itertools as I
x = []
a, b = I.repeat(x, 2)
a.append(4)
assert b is x and b == [4] and list(I.repeat(x, 0)) == []
Ejemplos
import itertools as I
print(list(I.repeat("x", 3)))
print(list(I.repeat("x", 0)))
Resultado
['x', 'x', 'x'] []
Para una lista todas las posiciones referencian el mismo objeto y ven sus cambios.