I have to sort my list of strings according to the months name:
my_list = ['apple_april', 'banana_july', 'carrot_december', 'dog_january']
I have to sort by january, february, martch, .....
My trial:
months = [m.split('_')[1] for m in my_list]
ans = [x for (y,x) in sorted(zip(months,my_list))]
But no success, how would you do it?
The expected answers is:
['dog_january', 'apple_april', 'banana_july', 'carrot_december']