0

I know this is probably a bad question, but if someone could help me out I would really appreciate it. I have a list of csv file paths that looks like this:

all_files = ['monthly_data\\2010_1.csv',
            'monthly_data\\2010_10.csv',
            'monthly_data\\2010_11.csv',
            'monthly_data\\2010_12.csv',
            'monthly_data\\2010_2.csv',
            'monthly_data\\2010_3.csv',
            'monthly_data\\2011_1.csv',
            'monthly_data\\2011_10.csv',
            'monthly_data\\2011_11.csv',
            'monthly_data\\2011_12.csv']
            'monthly_data\\2011_2.csv',
            'monthly_data\\2011_3.csv',

I am trying to sort the list so that the list looks like this

all_files = ['monthly_data\\2010_1.csv',
            'monthly_data\\2010_2.csv',
            'monthly_data\\2010_3.csv',
            'monthly_data\\2010_10.csv',
            'monthly_data\\2010_11.csv',
            'monthly_data\\2010_12.csv',
            'monthly_data\\2011_1.csv',
            'monthly_data\\2011_2.csv',
            'monthly_data\\2011_3.csv',
            'monthly_data\\2011_10.csv']
            'monthly_data\\2011_11.csv',
            'monthly_data\\2011_12.csv',

I realize that using

sorted(all_files)

does not work. I do not really understand why I guess. I would expect

'monthly_data\\2010_10.csv' > 'monthly_data\\2010_2.csv'

to evaluate to True, but it does not; it is actually the other way around. Why is this, and could someone think of a way to sort the list in the way I stated?

  • if you still have questions or that post doesn't do what you want feel free to ask me for clarification in comments here, sorting numbers alphabetically is odd but well documented. – Tadhg McDonald-Jensen Nov 09 '21 at 14:39

0 Answers0