CKTIS / Python
map()
Chiama su richiesta la funzione con un argomento posizionale da ogni ingresso.
Versione: Python 3.14; repository image, production runtime not attested
Sintassi
map(function, iterable, /, *iterables, strict=False)Chiama su richiesta la funzione con un argomento posizionale da ogni ingresso.
Le liste formano solo pow(2, 4), cioè 16, perché la seconda termina.
Python 3.14 ha aggiunto strict=True che solleva ValueError durante la lettura se le lunghezze differiscono.
it = map(pow, [2, 3], [4], strict=True)
assert next(it) == 16
try:
next(it)
except ValueError:
pass
else:
raise AssertionError
Esempi
print(list(map(pow, [2, 3], [4])))
try:
list(map(pow, [2, 3], [4], strict=True))
except ValueError as error:
print(type(error).__name__)
Risultato
[16] ValueError
Python 3.14 ha aggiunto strict=True che solleva ValueError durante la lettura se le lunghezze differiscono.