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


Groups > comp.lang.python > #65680

Re: Sorting dictionary by datetime value

Path csiph.com!v102.xanadu-bbs.net!xanadu-bbs.net!feeder.erje.net!eu.feeder.erje.net!news.stack.nl!newsfeed.xs4all.nl!newsfeed4a.news.xs4all.nl!xs4all!newsgate.cistron.nl!newsgate.news.xs4all.nl!post.news.xs4all.nl!not-for-mail
Return-Path <python.list@tim.thechases.com>
X-Original-To python-list@python.org
Delivered-To python-list@mail.python.org
X-Spam-Status OK 0.075
X-Spam-Evidence '*H*': 0.86; '*S*': 0.00; 'cc:addr:python-list': 0.11; '-tkc': 0.16; 'from:addr:python.list': 0.16; 'from:addr:tim.thechases.com': 0.16; 'from:name:tim chase': 0.16; 'igor': 0.16; 'iterating': 0.16; 'simplified': 0.16; 'sat,': 0.16; 'wrote:': 0.18; 'feb': 0.22; 'cc:addr:python.org': 0.22; 'cc:2**0': 0.24; 'purposes': 0.26; 'this:': 0.26; '(for': 0.26; 'header:In-Reply-To:1': 0.27; 'chris': 0.29; 'code': 0.31; 'keys': 0.31; 'could': 0.34; 'charset:us-ascii': 0.36; 'list': 0.37; 'pm,': 0.38; 'changed': 0.39; 'to:addr:gmail.com': 0.65; 'default': 0.69; 'behavior': 0.77; '7:25': 0.84; 'actually,': 0.84; 'dict,': 0.84; 'fail.': 0.84; 'received:50.22': 0.84
Date Sat, 8 Feb 2014 08:11:53 -0600
From Tim Chase <python.list@tim.thechases.com>
To Chris Angelico <rosuav@gmail.com>
Subject Re: Sorting dictionary by datetime value
In-Reply-To <CAPTjJmr83BOfsxpPL7m63S7ShJmo30B8e=Nv=+kVfOu_2bw1wQ@mail.gmail.com>
References <CA+FnnTxTvmSu922+Cg83jp8O_XdXXVnhQ1zaDEOd_41bONcoRQ@mail.gmail.com> <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> <CAPTjJmr83BOfsxpPL7m63S7ShJmo30B8e=Nv=+kVfOu_2bw1wQ@mail.gmail.com>
X-Mailer Claws Mail 3.8.1 (GTK+ 2.24.10; x86_64-pc-linux-gnu)
Mime-Version 1.0
Content-Type text/plain; charset=US-ASCII
Content-Transfer-Encoding 7bit
X-AntiAbuse This header was added to track abuse, please include it with any abuse report
X-AntiAbuse Primary Hostname - boston.accountservergroup.com
X-AntiAbuse Original Domain - python.org
X-AntiAbuse Originator/Caller UID/GID - [47 12] / [47 12]
X-AntiAbuse Sender Address Domain - tim.thechases.com
X-Get-Message-Sender-Via boston.accountservergroup.com: authenticated_id: tim@thechases.com
Cc "python-list@python.org" <python-list@python.org>
X-BeenThere python-list@python.org
X-Mailman-Version 2.1.15
Precedence list
List-Id General discussion list for the Python programming language <python-list.python.org>
List-Unsubscribe <https://mail.python.org/mailman/options/python-list>, <mailto:python-list-request@python.org?subject=unsubscribe>
List-Archive <http://mail.python.org/pipermail/python-list/>
List-Post <mailto:python-list@python.org>
List-Help <mailto:python-list-request@python.org?subject=help>
List-Subscribe <https://mail.python.org/mailman/listinfo/python-list>, <mailto:python-list-request@python.org?subject=subscribe>
Newsgroups comp.lang.python
Message-ID <mailman.6540.1391868679.18130.python-list@python.org> (permalink)
Lines 21
NNTP-Posting-Host 2001:888:2000:d::a6
X-Trace 1391868679 news.xs4all.nl 2915 [2001:888:2000:d::a6]:37639
X-Complaints-To abuse@xs4all.nl
Xref csiph.com comp.lang.python:65680

Show key headers only | View raw


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


Thread

Re: Sorting dictionary by datetime value Tim Chase <python.list@tim.thechases.com> - 2014-02-08 08:11 -0600

csiph-web