Groups | Search | Server Info | Keyboard shortcuts | Login | Register [http] [https] [nntp] [nntps]


Groups > comp.lang.python > #65647 > unrolled thread

Re: Sorting dictionary by datetime value

Started byChris Angelico <rosuav@gmail.com>
First post2014-02-08 19:29 +1100
Last post2014-02-08 19:29 +1100
Articles 1 — 1 participant

Back to article view | Back to comp.lang.python

This discussion starts older than the indexed window; earlier articles aren't shown. The article labeled Started by below is the oldest one visible, not the original post.


Contents

  Re: Sorting dictionary by datetime value Chris Angelico <rosuav@gmail.com> - 2014-02-08 19:29 +1100

#65647 — Re: Sorting dictionary by datetime value

FromChris Angelico <rosuav@gmail.com>
Date2014-02-08 19:29 +1100
SubjectRe: Sorting dictionary by datetime value
Message-ID<mailman.6524.1391848158.18130.python-list@python.org>
On Sat, Feb 8, 2014 at 7:25 PM, Igor Korot <ikorot01@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

[toc] | [standalone]


Back to top | Article view | comp.lang.python


csiph-web