blah
0
Q:

convert list of strings to ints python

test_list = ['1', '4', '3', '6', '7'] 

int_list = [int(i) for i in test_list]
6
# Python3 code to demonstrate  
# converting list of strings to int 
# using map() 
  
# initializing list  
test_list = ['1', '4', '3', '6', '7'] 
  
# Printing original list 
print ("Original list is : " + str(test_list)) 
  
# using map() to 
# perform conversion 
test_list = list(map(int, test_list)) 
      
  
# Printing modified list  
print ("Modified list is : " + str(test_list)) 
4
# Example usage using list comprehension:
# Say you have the following list of lists of strings and want integers
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]]
1
# initializing list  
test_list = ['1', '4', '3', '6', '7'] 

# using list comprehension to 
# perform conversion 
test_list = [int(i) for i in test_list]
1
test_list = ['1', '4', '3', '6', '7'] 
  
# Printing original list 
print ("Original list is : " + str(test_list)) 
  
# using naive method to 
# perform conversion 
for i in range(0, len(test_list)): 
    test_list[i] = int(test_list[i]) 
      
  
# Printing modified list  
print ("Modified list is : " + str(test_list)) 
-1

New to Communities?

Join the community