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 215 views
1 answer 200 views
2 answers 242 views
1 answer 158 views
1 answer 118 views
...