How to sort list by alphanumeric values
a = ['v1_0005.jpg', 'v1_00015.jpg', 'v2_0007.jpg', 'v2_0002.jpg']
while sorting list using a.sort() I get
['v1_0005.jpg', 'v1_00015.jpg', 'v2_0007.jpg', 'v2_0002.jpg']
which means sorting order is wrong, I expect list is sort by alphanumeric value in python
Expected list to be :
['v2_0002.jpg','v1_0005.jpg','v2_0007.jpg', 'v1_00015.jpg']
a.sort()i get" (sort instead of list) ?'v1_00017.jpg'is less than'v1_0002.jpg', because the first differing character is'1'vs.'2', and'1'<'2'. If you want to do a more advanced sort, you'll need to extract the numeric portion from the string and convert it to a number.