Sorting dictionary by datetime value
rosuav at gmail.com
Sat Feb 8 09:29:09 CET 2014
On Sat, Feb 8, 2014 at 7:25 PM, Igor Korot <ikorot01 at gmail.com> wrote:
>> Try this:
>> sorted_items = sorted(my_dict.keys(), key=my_dict.get)
>> for key in sorted_items:
>> print my_dict[key], key
> This code fail.
> sorted_item is a list of tuples. And so iterating the list in the for loop I
> will get a tuple.
> It probably should be:
> for key in sorted_items:
> Let me try that.
Actually, it's a list of keys - notice that I changed my_dict.items()
More information about the Python-list