convert a list of string to int python code example
Example 1: convert list of strings to ints python
test_list = ['1', '4', '3', '6', '7']
int_list = [int(i) for i in test_list]
Example 2: change list to int in python
test_list = list(map(int,test_list))
Example 3: change string list to int list python
Use the map function (in Python 2.x):
results = map(int, results)
In Python 3, you will need to convert the result from map to a list:
results = list(map(int, results))
Example 4: python convert list of strings to list of integers
list_of_ints = [int(i) for i in list_of_strings]
list_of_strings = ['2', '3', '47']
list_of_ints = [int(i) for i in list_of_strings]
print(list_of_ints)
--> [2, 3, 47]
Example 5: convert list into integer python
num = [1, 2, 3, 4]
s = [str(i) for i in num]
result = str("".join(s))
print(result)
Example 6: convert list of strings to int python
test_list = ['1', '4', '3', '6', '7']
print ("Original list is : " + str(test_list))
for i in range(0, len(test_list)):
test_list[i] = int(test_list[i])
print ("Modified list is : " + str(test_list))