While many examples succeed in using hints to describe the items carried by a list, I'm stumbling in their declarations.
I'm willing to manipulate (receive, return, create internally) lists of integers.
Accordingly, I'm using list[int]
to mention them.
But my code fails with the message: TypeError: 'type' object is not subscriptable, at the first (def
) line.
def filtre_valeurs_paires(valeurs: list[int]) -> list[int]:
valeurs_entieres: list[int] = list(filter(lambda valeur: valeur % 2 == 0, valeurs));
return valeurs_entieres;
candidats: list[int] = [5, 8, -2, 23, 11, 4];
print("Les valeurs paires dans {} sont : {}".format(candidats, filtre_valeurs_paires(candidats)));
The desired output is a list of even integers: [8, -2, 4].