I would like to sort a list of subfolder names by Python but it does not work in the desired manner.
files = ['file_37.png', 'file_8.png', 'file_13.png', 'file_114.png', 'file_115.png']
sorted(files)
Output:
['file_114.png', 'file_115.png', 'file_13.png', 'file_37.png', 'file_8.png']
Apparently, Python is sorting the names in a dictionary form without considering the integer value of the digit after '_'. However, what I want to get is:
['file_8.png', 'file_13.png', 'file_37.png','file_114.png', 'file_115.png']
Can anyone tell me how to get this desired output in Python?