convert list string objects to integer 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: python convert list of lists of strings to int
x = [['565.0', '575.0'], ['1215.0', '245.0'], ['1740.0', '245.0']]
list_of_integers = [[int(float(j)) for j in i] for i in x]
print(list_of_integers)
--> [[565, 575], [1215, 245], [1740, 245]]
Example 3: 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))