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


Groups > comp.lang.python > #65647

Re: Sorting dictionary by datetime value

Path csiph.com!v102.xanadu-bbs.net!xanadu-bbs.net!feeder.erje.net!eu.feeder.erje.net!newsfeed.xs4all.nl!newsfeed2.news.xs4all.nl!xs4all!post.news.xs4all.nl!not-for-mail
Return-Path <rosuav@gmail.com>
X-Original-To python-list@python.org
Delivered-To python-list@mail.python.org
X-Spam-Status OK 0.039
X-Spam-Evidence '*H*': 0.92; '*S*': 0.00; 'cc:addr:python-list': 0.11; 'be:': 0.16; 'from:addr:rosuav': 0.16; 'from:name:chris angelico': 0.16; 'igor': 0.16; 'iterating': 0.16; 'tuple.': 0.16; 'sat,': 0.16; 'wrote:': 0.18; 'feb': 0.22; 'cc:addr:python.org': 0.22; 'print': 0.22; 'cc:2**0': 0.24; 'this:': 0.26; 'header:In- Reply-To:1': 0.27; 'message-id:@mail.gmail.com': 0.30; 'code': 0.31; 'that.': 0.31; 'keys': 0.31; 'probably': 0.32; 'received:google.com': 0.35; 'should': 0.36; 'list': 0.37; 'pm,': 0.38; 'changed': 0.39; '7:25': 0.84; 'actually,': 0.84; 'fail.': 0.84; 'to:none': 0.92
DKIM-Signature v=1; a=rsa-sha256; c=relaxed/relaxed; d=gmail.com; s=20120113; h=mime-version:in-reply-to:references:date:message-id:subject:from:cc :content-type; bh=pA1/31WxgLEyQeHn8qNtIncG4gC6LcmBvcnfLtvCZoM=; b=drWLjf3mod/U0m4FXkzrS5QrQyfNfpp5p7H71Jpyd2cDsAnVwKeDyHTfh4GfBhMXcn DlvrKa+PR8c+W5FkJho/PPtP0w7kg1ur/BGchE0N5rRAbvk7UpRnBL25XIV7ubMpCguZ kLHdQL73uybR1mWCeLb6Ml+QfTa+wB8AtDZXwtP+uNPiPCOIL+/PxdsnmZ8K+LYcXn4r bj1ZktmvMeXE3uc+3glIHVKceodAXpgdZWOxw5bW8WjG8a/zUT5M/ZYR5Z5BRbsbuMau cwec6b77pVznBfeAWqsHqsMBowBpOfPsHj12fazCKhwizIlpG4RVD0MNX98+RE1EGIRs tyKA==
MIME-Version 1.0
X-Received by 10.66.129.133 with SMTP id nw5mr12909539pab.98.1391848149194; Sat, 08 Feb 2014 00:29:09 -0800 (PST)
In-Reply-To <CA+FnnTxae8u3m+LS-KfkNwO22x3MRV7kvQgjhegWzTV9WshUzA@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>
Date Sat, 8 Feb 2014 19:29:09 +1100
Subject Re: Sorting dictionary by datetime value
From Chris Angelico <rosuav@gmail.com>
Cc "python-list@python.org" <python-list@python.org>
Content-Type text/plain; charset=UTF-8
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.6524.1391848158.18130.python-list@python.org> (permalink)
Lines 22
NNTP-Posting-Host 2001:888:2000:d::a6
X-Trace 1391848158 news.xs4all.nl 2922 [2001:888:2000:d::a6]:60118
X-Complaints-To abuse@xs4all.nl
Xref csiph.com comp.lang.python:65647

Show key headers only | 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