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


Groups > comp.lang.python > #65647

Re: Sorting dictionary by datetime value

References (1 earlier) <CAPTjJmqDusdFC1eLbU6LF5-up__LAE-63ii0UUvAGGNem9U4+w@mail.gmail.com> <CA+FnnTz8PLn=usNyotgC6fRKVsjL6DKt9PSd4Koudwvxi3BBcw@mail.gmail.com> <CAPTjJmq9b2gs_61X2uupV-CHtknu3Pna2BUu6C3zUrpHPZw08w@mail.gmail.com> <CA+FnnTwtrsADM2G2zRrGg7SBB5K8cEhnhaFc_n6QYomCGqUhQA@mail.gmail.com> <CA+FnnTxae8u3m+LS-KfkNwO22x3MRV7kvQgjhegWzTV9WshUzA@mail.gmail.com>
Date 2014-02-08 19:29 +1100
Subject Re: Sorting dictionary by datetime value
From Chris Angelico <rosuav@gmail.com>
Newsgroups comp.lang.python
Message-ID <mailman.6524.1391848158.18130.python-list@python.org> (permalink)

Show all headers | View raw


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

Back to comp.lang.python | Previous | Next | Find similar | Unroll thread


Thread

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

csiph-web