How to convert all strings in a list to int in Python

2 Answers

0 votes
a_list = ['1', '2', '3', '4', '5']

a_list = list(map(int, a_list))

print(a_list)

'''
run:

[1, 2, 3, 4, 5]

'''

 



answered Oct 20, 2017 by avibootz
0 votes
a_list = ['1', '2', '3', '4', '5']

a_list = [int(i) for i in a_list]

print(a_list)

'''
run:

[1, 2, 3, 4, 5]

'''

 



answered Oct 20, 2017 by avibootz
...