Path: csiph.com!v102.xanadu-bbs.net!xanadu-bbs.net!news.albasani.net!news.stack.nl!newsfeed.xs4all.nl!newsfeed2a.news.xs4all.nl!xs4all!newsgate.cistron.nl!newsgate.news.xs4all.nl!post.news.xs4all.nl!not-for-mail Return-Path: X-Original-To: python-list@python.org Delivered-To: python-list@mail.python.org X-Spam-Status: OK 0.050 X-Spam-Evidence: '*H*': 0.90; '*S*': 0.00; 'worked.': 0.09; '>>': 0.16; 'be:': 0.16; 'igor': 0.16; 'iterating': 0.16; 'tuple.': 0.16; 'sat,': 0.16; 'wrote:': 0.18; 'feb': 0.22; 'email addr:gmail.com>': 0.22; 'print': 0.22; '>': 0.26; 'this:': 0.26; 'header:In-Reply-To:1': 0.27; 'chris': 0.29; 'am,': 0.29; 'message-id:@mail.gmail.com': 0.30; 'url:mailman': 0.30; 'code': 0.31; 'that.': 0.31; 'keys': 0.31; 'probably': 0.32; 'url:python': 0.33; 'no,': 0.35; 'received:google.com': 0.35; 'url:listinfo': 0.36; "didn't": 0.36; 'url:org': 0.36; 'should': 0.36; 'list': 0.37; 'thank': 0.38; 'to:addr:python-list': 0.38; 'pm,': 0.38; 'to:addr:python.org': 0.39; 'changed': 0.39; 'url:mail': 0.40; 'you.': 0.62; '7:25': 0.84; 'actually,': 0.84; 'fail.': 0.84 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:to :content-type; bh=6yKMUvDWQ+II9xUutQWWHPDKzFgNZXXz63IGIs5bbYo=; b=sGzUkWAK33N5LnNJAyDPcbOnHJpnZfm8DH0WS9a6YnhBgtH50FUfIGFe9WKDTh+1wh z2LexpaL1vw0y9ZO0/8oHVoQlHQ8aHW9FhtdUY0YQMF3TAXzmxDcWXlFWEUh4pYJ0EYA oPY+7nhOZ7vUcrI+QxJwFz97eveL40Do/t9fJee82B5HiCEEzyEskCpKWj2tNLa3v2Po En7zF3U5GADR7IvAny2nDOvdnpeHSc1SeGOXuqyGBpIplcsNfcr47XsACctOtW2357A6 U0r1lUCP0dDvHsiUhMoV/5zzJJ2GkGDuGlfTmeUSyojU3vb0TM9zYIwFMO25sr5Nce9U 9BbQ== MIME-Version: 1.0 X-Received: by 10.220.106.84 with SMTP id w20mr14236374vco.18.1391848528989; Sat, 08 Feb 2014 00:35:28 -0800 (PST) In-Reply-To: References: Date: Sat, 8 Feb 2014 00:35:28 -0800 Subject: Re: Sorting dictionary by datetime value From: Igor Korot To: python-list@python.org Content-Type: multipart/alternative; boundary=047d7b3435c026d0fe04f1e0fd41 X-BeenThere: python-list@python.org X-Mailman-Version: 2.1.15 Precedence: list List-Id: General discussion list for the Python programming language List-Unsubscribe: , List-Archive: List-Post: List-Help: List-Subscribe: , Newsgroups: comp.lang.python Message-ID: Lines: 79 NNTP-Posting-Host: 2001:888:2000:d::a6 X-Trace: 1391848537 news.xs4all.nl 2913 [2001:888:2000:d::a6]:37055 X-Complaints-To: abuse@xs4all.nl Xref: csiph.com comp.lang.python:65649 --047d7b3435c026d0fe04f1e0fd41 Content-Type: text/plain; charset=ISO-8859-1 Thank you. That worked. And no, I didn't notice that change. :( On Sat, Feb 8, 2014 at 12:29 AM, Chris Angelico wrote: > On Sat, Feb 8, 2014 at 7:25 PM, Igor Korot 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 > -- > https://mail.python.org/mailman/listinfo/python-list > --047d7b3435c026d0fe04f1e0fd41 Content-Type: text/html; charset=ISO-8859-1 Content-Transfer-Encoding: quoted-printable
Thank you. That worked.
And no, I didn't notice th= at change. :(


On Sat, Feb 8, 2014 at 12:29 AM, Chris Angelico <<= a href=3D"mailto:rosuav@gmail.com" target=3D"_blank">rosuav@gmail.com&g= t; wrote:
On Sat, Feb 8, 2014 at 7:25 = PM, Igor Korot <ikorot01@gmail.com= > wrote:
>> Try this:
>>
>> sorted_items =3D sorted(my_dict.keys(), key=3Dmy_dict.get)
>> for key in sorted_items:
>> =A0 =A0 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.ite= ms()
into my_dict.keys()?

ChrisA
--
https://mail.python.org/mailman/listinfo/python-list

--047d7b3435c026d0fe04f1e0fd41--