python sort isdigit

Solutions on MaxInterview for python sort isdigit by the best coders in the world

showing results for - "python sort isdigit"
Sara
23 Aug 2019
1>>> ''.join(filter(str.isdigit, 'image101.jpg'))
2'101'
3>>> int(''.join(filter(str.isdigit, 'image101.jpg')))
4101
Lorenzo
15 Oct 2017
1>>> my_list= ['image101.jpg', 'image2.jpg', 'image1.jpg']
2>>> my_list.sort(key=lambda x: int(''.join(filter(str.isdigit, x))))
3>>> my_list
4['image1.jpg', 'image2.jpg', 'image101.jpg']
Camille
15 Jun 2018
1from natsort import natsorted
2my_list = ['image101.jpg', 'image2.jpg', 'image1.jpg']
3natsorted(my_list)