What is the easiest way to convert list with str into list with int in Python? For example, we have to convert ['1', '2', '3'] to [1, 2, 3]. Of course, we can use a for loop, but it's too easy.
str
int
['1', '2', '3']
[1, 2, 3]
for
Python 2.x:
map(int, ["1", "2", "3"])
Python 3.x (in 3.x, map returns an iterator, not a list as in 2.x):
map
list(map(int, ["1", "2", "3"]))
map documentation: 2.6, 3.1
1.4m articles
1.4m replys
5 comments
57.0k users