Possible en double:
What is the easiest way to convert list with str into list with int? =)Listes en Python
Est-il possible de transformer:
a = [ '1', '2', '3', ' 4 ']
à
a = [1, 2, 3, 4]
Merci!
Possible en double:
What is the easiest way to convert list with str into list with int? =)Listes en Python
Est-il possible de transformer:
a = [ '1', '2', '3', ' 4 ']
à
a = [1, 2, 3, 4]
Merci!
Vous pouvez utiliser map
pour appliquer une fonction à chaque élément d'une liste, et obtenir la liste résultante (Python 2.x)/itérable (Python 3.x).
map(int, a)
Cela pourrait être fait avec la compréhension de la liste aussi.
[int(x) for x in a]