Groups | Search | Server Info | Keyboard shortcuts | Login | Register [http] [https] [nntp] [nntps]
Groups > comp.lang.python > #65680
| Date | 2014-02-08 08:11 -0600 |
|---|---|
| From | Tim Chase <python.list@tim.thechases.com> |
| Subject | Re: Sorting dictionary by datetime value |
| References | (2 earlier) <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> <CAPTjJmr83BOfsxpPL7m63S7ShJmo30B8e=Nv=+kVfOu_2bw1wQ@mail.gmail.com> |
| Newsgroups | comp.lang.python |
| Message-ID | <mailman.6540.1391868679.18130.python-list@python.org> (permalink) |
On 2014-02-08 19:29, Chris Angelico wrote: > 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) > > > > This code fail. > > Actually, it's a list of keys - notice that I changed > my_dict.items() into my_dict.keys()? Unless you need to make a copy (for purposes of altering the original while iterating), that's the default behavior of iterating over a dict, so it could be simplified to sorted_items = sorted(my_dict, key=my_dict.get) -tkc
Back to comp.lang.python | Previous | Next | Find similar | Unroll thread
Re: Sorting dictionary by datetime value Tim Chase <python.list@tim.thechases.com> - 2014-02-08 08:11 -0600
csiph-web