Skip to content Skip to sidebar Skip to footer

Python 3.5: Sort Dictionary By Key (dates)

I'm new to Python and I'm trying to sort a dictionary by key. The keys are datetime objects. It works for 1 April, 2 April, 3 April, but it puts 4 april between 1 and 2. I've tried

Solution 1:

Just like said in the comments, the dictionary sorted strings instead of datetime objects. So the solution is to return date, and format the date in the write file function.

Thanks for the fast answers!

Post a Comment for "Python 3.5: Sort Dictionary By Key (dates)"