Psiloc
0
Q:

python convert list of strings to list of integers

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

int_list = [int(i) for i in test_list]
6
# Basic syntax:
int_list = [int(i) for i in list]

# Example usage with list comprehension:
list_of_strings = ['2', '3', '47']
list_of_integers = [int(i) for i in list_of_strings]
print(list_of_integers)
--> [2, 3, 47]
2
# 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