Answers for "python sort isdigit"

0

python sort isdigit

>>> ''.join(filter(str.isdigit, 'image101.jpg'))
'101'
>>> int(''.join(filter(str.isdigit, 'image101.jpg')))
101
Posted by: Guest on May-28-2020
0

python sort isdigit

from natsort import natsorted
my_list = ['image101.jpg', 'image2.jpg', 'image1.jpg']
natsorted(my_list)
Posted by: Guest on May-28-2020
0

python sort isdigit

>>> my_list= ['image101.jpg', 'image2.jpg', 'image1.jpg']
>>> my_list.sort(key=lambda x: int(''.join(filter(str.isdigit, x))))
>>> my_list
['image1.jpg', 'image2.jpg', 'image101.jpg']
Posted by: Guest on May-28-2020

Python Answers by Framework

Browse Popular Code Answers by Language