Path: csiph.com!v102.xanadu-bbs.net!xanadu-bbs.net!feeder.erje.net!eu.feeder.erje.net!newsfeed.freenet.ag!news2.euro.net!newsfeed.xs4all.nl!newsfeed2.news.xs4all.nl!xs4all!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.010 X-Spam-Evidence: '*H*': 0.98; '*S*': 0.00; 'charset:iso-8859-7': 0.04; 'seemed': 0.09; 'subject:set': 0.09; 'cc:addr:python-list': 0.11; "'''": 0.16; 'key)': 0.16; 'set()': 0.16; 'subject:fails': 0.16; 'too?': 0.16; 'subject: ?': 0.16; 'wrote:': 0.18; 'email addr:gmail.com>': 0.22; 'cc:addr:python.org': 0.22; 'cc:2**0': 0.24; 'cc:no real name:2**0': 0.24; '>': 0.26; 'header:In- Reply-To:1': 0.27; 'tried': 0.27; 'message-id:@mail.gmail.com': 0.30; 'tuples': 0.31; 'totally': 0.33; 'skip:s 30': 0.35; 'but': 0.35; 'received:google.com': 0.35; 'really': 0.36; 'being': 0.38; 'skip:& 10': 0.38; 'to:addr:gmail.com': 0.65; '8bit%:57': 0.74; 'frustrating': 0.84; '2013': 0.98 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 :cc:content-type; bh=GIKf7RYQUwe20jThqe1R6jyjE9Ogkde7800pj5ci5NA=; b=AjikX7CUuQ3eKYIdyPxp0YQiyoL0R6mX8D1yoJSfoJ+hLRr5+D+oh35/NzVev+wm60 XVJjJDbIQzf4E7zI/yckxqsOnZY7mMJmtLFJ+RlFWXXmbc42kf2pbmnX4c7vZqbRJrKO 2M5/BK1aaYbo+HRFr9/O5rzbUc2SmPUJbYPGuuaRiY4bjHCejh459ESUv1vFaYFc+GFP 8oVH8aaI2FjmAboij09V6uDyXk13xpHmZa31CpnYEWF8NkBM0gGDnqUy8fbTYYUa+Hpk GK6eeVPTK7BvfacH953m24cQG8d3+Il1yT4cJRcwYR6+vJBRros7ojsYZS4GKzkQYZoY VozQ== MIME-Version: 1.0 X-Received: by 10.49.24.13 with SMTP id q13mr10167189qef.49.1370859189538; Mon, 10 Jun 2013 03:13:09 -0700 (PDT) In-Reply-To: <56f10268-0e26-4f86-ae03-8fd740cc4544@googlegroups.com> References: <3b252a10-a7e3-40f5-99dc-8afcf72cf997@googlegroups.com> <7c0e481e-97dd-4d36-808c-88e3580d8311@googlegroups.com> <56f10268-0e26-4f86-ae03-8fd740cc4544@googlegroups.com> Date: Mon, 10 Jun 2013 11:13:09 +0100 Subject: Re: Sorting a set works, sorting a dictionary fails ? From: =?ISO-8859-1?Q?F=E1bio_Santos?= To: =?ISO-8859-7?B?zenq/Ovh7/Igyu/98eHy?= Content-Type: multipart/alternative; boundary=047d7b2e745c07985404deca0721 Cc: 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 List-Unsubscribe: , List-Archive: List-Post: List-Help: List-Subscribe: , Newsgroups: comp.lang.python Message-ID: Lines: 65 NNTP-Posting-Host: 2001:888:2000:d::a6 X-Trace: 1370859197 news.xs4all.nl 15926 [2001:888:2000:d::a6]:35760 X-Complaints-To: abuse@xs4all.nl Xref: csiph.com comp.lang.python:47540 --047d7b2e745c07985404deca0721 Content-Type: text/plain; charset=ISO-8859-7 Content-Transfer-Encoding: quoted-printable On 10 Jun 2013 10:53, "=CD=E9=EA=FC=EB=E1=EF=F2 =CA=EF=FD=F1=E1=F2" wrote: > > After many tried this did the job: > > for key in sorted(months.items(),key=3Dlambda num : num[1]): > print(''' > > ''' % (key[1], key[0]) ) > > > but its really frustrating not being able to: > > for key in sorted( months.values() ): > print(''' > > ''' % (months[key], key) ) > > Which seemed to be an abivous way to do it. > names set() was able to order like this why not the dictionary too? Why not for key, value in sorted(d.items()): Tuples are totally sortable. --047d7b2e745c07985404deca0721 Content-Type: text/html; charset=ISO-8859-7 Content-Transfer-Encoding: quoted-printable


On 10 Jun 2013 10:53, "=CD=E9=EA=FC=EB=E1=EF=F2 =CA=EF=FD=F1=E1=F2&quo= t; <nikos.gr33k@gmail.com&g= t; wrote:
>
> After many tried this did the job:
>
> for key in sorted(months.items(),key=3Dlambda num : num[1]):
> =A0 =A0 =A0 =A0 print('''
> =A0 =A0 =A0 =A0 =A0 =A0 =A0 =A0 <option value=3D"%s"> = %s </option>
> =A0 =A0 =A0 =A0 ''' % (key[1], key[0]) )
>
>
> but its really frustrating not being able to:
>
> for key in sorted( months.values() ):
> =A0 =A0 =A0 =A0 print('''
> =A0 =A0 =A0 =A0 =A0 =A0 =A0 =A0 <option value=3D"%s"> = %s </option>
> =A0 =A0 =A0 =A0 ''' % (months[key], key) )
>
> Which seemed to be an abivous way to do it.
> names set() was able to order like this why not the dictionary too?

Why not

for key, value in sorted(d.items()):

Tuples are totally sortable.

--047d7b2e745c07985404deca0721--