I have a list of directories and I would like to sort the list based on the date followed by a number. Here is an example of the unsorted list:
L = ['C:\\Users\\...\\file1\\sample_nov1_1',
'C:\\Users\\...\\file2\\sample_sep1_1',
'C:\\Users\\...\\file3\\sample_oct15_2',
'C:\\Users\\...\\file2\\sample_sep1_2',
'C:\\Users\\...\\file4\\sample_sep10_2',
'C:\\Users\\...\\file4\\sample_sep10_1']
I would like to sort it so I get the following output:
['C:\\Users\\...\\sample_sep1_1',
'C:\\Users\\...\\sample_sep1_2',
'C:\\Users\\...\\sample_sep10_1',
'C:\\Users\\...\\sample_sep10_2',
'C:\\Users\\...\\sample_oct15_1',
'C:\\Users\\...\\sample_nov1_2']
I get this list by making a walk from a parent directories, but because these files were not created chronologically in the same order that I want the output, I am not sure if I can modify that part of the code. I have already looked at a few other answers such as this one, but they do not have the same complications that I have here. How can I achieve this? I suppose using regular expressions I might be able to simplify a bit, but not sure if that is the correct approach.