Sorting dictionary by datetime value

Igor Korot ikorot01 at gmail.com
Sat Feb 8 09:35:28 CET 2014


Thank you. That worked.
And no, I didn't notice that change. :(


On Sat, Feb 8, 2014 at 12:29 AM, Chris Angelico <rosuav at gmail.com> wrote:

> 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[1] in sorted_items:
> >
> > Let me try that.
> >
>
> Actually, it's a list of keys - notice that I changed my_dict.items()
> into my_dict.keys()?
>
> ChrisA
> --
> https://mail.python.org/mailman/listinfo/python-list
>
-------------- next part --------------
An HTML attachment was scrubbed...
URL: <http://mail.python.org/pipermail/python-list/attachments/20140208/f675766b/attachment.html>


More information about the Python-list mailing list