How to convert a list of string into a sorted list of integers in Python

2 Answers

0 votes
lst = ['31', '889', '4', '198', '109'] 
  
sorted_int_lst = sorted(map(int, lst)) 
  
print(sorted_int_lst) 



'''
run:

[4, 31, 109, 198, 889]

'''

 



answered Jan 10, 2021 by avibootz
0 votes
lst = ['31', '889', '4', '198', '109'] 
  
sorted_int_lst = sorted(int(i) for i in lst) 
  
print(sorted_int_lst) 



'''
run:

[4, 31, 109, 198, 889]

'''

 



answered Jan 10, 2021 by avibootz

Related questions

2 answers 204 views
1 answer 147 views
1 answer 186 views
2 answers 230 views
1 answer 111 views
...