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


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

Re: Sorting dictionary by datetime value

Started byTim Chase <python.list@tim.thechases.com>
First post2014-02-08 08:11 -0600
Last post2014-02-08 08:11 -0600
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 Tim Chase <python.list@tim.thechases.com> - 2014-02-08 08:11 -0600

#65680 — Re: Sorting dictionary by datetime value

FromTim Chase <python.list@tim.thechases.com>
Date2014-02-08 08:11 -0600
SubjectRe: Sorting dictionary by datetime value
Message-ID<mailman.6540.1391868679.18130.python-list@python.org>
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

[toc] | [standalone]


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


csiph-web