Path: csiph.com!v102.xanadu-bbs.net!xanadu-bbs.net!feeder.erje.net!eu.feeder.erje.net!xlned.com!feeder1.xlned.com!newsfeed.xs4all.nl!newsfeed1.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.005 X-Spam-Evidence: '*H*': 0.99; '*S*': 0.00; 'charset:iso-8859-7': 0.04; 'output': 0.05; 'key.': 0.09; 'subject:set': 0.09; 'cc:addr :python-list': 0.11; 'python': 0.11; "'''": 0.16; 'integers.': 0.16; 'key)': 0.16; 'keyerror': 0.16; 'subject:fails': 0.16; 'subject: ?': 0.16; 'wrote:': 0.18; 'trying': 0.19; 'meant': 0.20; '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; 'sort': 0.25; '>': 0.26; 'skip:" 40': 0.26; 'this:': 0.26; 'header:In-Reply- To:1': 0.27; 'message-id:@mail.gmail.com': 0.30; 'url:mailman': 0.30; "skip:' 10": 0.31; 'keyerror:': 0.31; 'skip:7 10': 0.31; 'file': 0.32; 'url:python': 0.33; 'received:google.com': 0.35; 'there': 0.35; 'url:listinfo': 0.36; 'url:org': 0.36; 'skip:& 10': 0.38; 'url:mail': 0.40; 'tell': 0.60; 'to:addr:gmail.com': 0.65; '8bit%:57': 0.74; '8bit%:60': 0.84; '8bit%:67': 0.93; '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=U6h6yi1J+UBFOjHoN6v6uvo4glTwz0cVRka5QdxBSIs=; b=u2um/V+1K6VqHCP1zycE+IjoxEYjIfRiihvtYIC3jMhlIPve2dUSvfiAbjeryRx00f 7EByyLrPgxVwxYkDc3EI1GoStZ0wrpFx4FKr+Sqkml8OsotZ6dDS3Q8V+pgCZFigcBv5 XjHh/w5BYS/+osSaUzWXL4BYYLtI3c6yNGw9mYwPH/OJkrx9wx47y/dFlxeCDkqKUQjE Xbb5/Y+9kHxpM9g/pLe0EVX4NQba+HYB6C0hsMwjQ3E0Bsidc6rxL+znPYDAanILDgDE NbCvHi8iplbE54Z0YfqlQGipMgU6D2PCy8PrmqAJZFrvEjvfSEp0zhErSK845IeBkjPD s0cA== MIME-Version: 1.0 X-Received: by 10.229.133.65 with SMTP id e1mr3615424qct.105.1370856434294; Mon, 10 Jun 2013 02:27:14 -0700 (PDT) In-Reply-To: References: <3b252a10-a7e3-40f5-99dc-8afcf72cf997@googlegroups.com> Date: Mon, 10 Jun 2013 10:27:14 +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=e89a8f50389ccdec9104dec9622a 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: 89 NNTP-Posting-Host: 2001:888:2000:d::a6 X-Trace: 1370856443 news.xs4all.nl 15904 [2001:888:2000:d::a6]:47121 X-Complaints-To: abuse@xs4all.nl Xref: csiph.com comp.lang.python:47536 --e89a8f50389ccdec9104dec9622a Content-Type: text/plain; charset=ISO-8859-7 Content-Transfer-Encoding: quoted-printable On 10 Jun 2013 09:34, "=CD=E9=EA=FC=EB=E1=EF=F2 =CA=EF=FD=F1=E1=F2" wrote: > > Trying this: > > months =3D { '=C9=E1=ED=EF=F5=DC=F1=E9=EF=F2':1, '=D6=E5=E2=F1=EF=F5=DC= =F1=E9=EF=F2':2, '=CC=DC=F1=F4=E9=EF=F2':3, '=C1=F0=F1=DF=EB=E9=EF=F2':4, '=CC=DC=FA=EF=F2':5, '=C9=EF=FD=ED=E9=EF=F2':6, \ > '=C9=EF=FD=EB=E9=EF=F2':7, '=C1=FD=E3=EF=F5=F3=F4=EF=F2':8, '= =D3=E5=F0=F4=DD=EC=E2=F1=E9=EF=F2':9, '=CF=EA=F4=FE=E2=F1=E9=EF=F2':10, '=CD=EF=DD=EC=E2=F1=E9=EF=F2':11, '=C4=E5=EA=DD=EC=E2=F1=E9=EF=F2':12 } > > for key in sorted( months.values() ): > print(''' > > ''' % (months[key], key) ) > > > output this: > > [Mon Jun 10 11:25:11 2013] [error] [client 79.103.41.173] File "/home/nikos/public_html/cgi-bin/pelatologio.py", line 310, in , referer: http://superhost.gr/ > [Mon Jun 10 11:25:11 2013] [error] [client 79.103.41.173] ''' % (months[key], key) ), referer: http://superhost.gr/ > [Mon Jun 10 11:25:11 2013] [error] [client 79.103.41.173] KeyError: 1, referer: http://superhost.gr/ > > KeyError 1 ??!! All i did was to tell python to sort the dictionary values, which are just integers. > -- > http://mail.python.org/mailman/listinfo/python-list KeyError: 1 means that there is no int(1) key. I think you meant to do "for key in sorted(yourdict.keys())" --e89a8f50389ccdec9104dec9622a Content-Type: text/html; charset=ISO-8859-7 Content-Transfer-Encoding: quoted-printable


On 10 Jun 2013 09:34, "=CD=E9=EA=FC=EB=E1=EF=F2 =CA=EF=FD=F1=E1=F2&quo= t; <nikos.gr33k@gmail.com&g= t; wrote:
>
> Trying this:
>
> months =3D { '=C9=E1=ED=EF=F5=DC=F1=E9=EF=F2':1, '=D6=E5= =E2=F1=EF=F5=DC=F1=E9=EF=F2':2, '=CC=DC=F1=F4=E9=EF=F2':3, '= ;=C1=F0=F1=DF=EB=E9=EF=F2':4, '=CC=DC=FA=EF=F2':5, '=C9=EF= =FD=ED=E9=EF=F2':6, \
> =A0 =A0 =A0 =A0 =A0 =A0'=C9=EF=FD=EB=E9=EF=F2':7, '=C1=FD= =E3=EF=F5=F3=F4=EF=F2':8, '=D3=E5=F0=F4=DD=EC=E2=F1=E9=EF=F2':9= , '=CF=EA=F4=FE=E2=F1=E9=EF=F2':10, '=CD=EF=DD=EC=E2=F1=E9=EF= =F2':11, '=C4=E5=EA=DD=EC=E2=F1=E9=EF=F2':12 }
>
> 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) )
>
>
> output this:
>
> [Mon Jun 10 11:25:11 2013] [error] [client 79.103.41.173] =A0 File &qu= ot;/home/nikos/public_html/cgi-bin/pelatologio.py", line 310, in <m= odule>, referer: http://superhost.gr/
> [Mon Jun 10 11:25:11 2013] [error] [client 79.103.41.173] =A0 =A0 '= ;'' % (months[key], key) ), referer:
http://superhost.gr/
> [Mon Jun 10 11:25:11 2013] [error] [client 79.103.41.173] KeyError: 1,= referer: http://superhost.gr/
>
> KeyError 1 ??!! All i did was to tell python to sort the dictionary va= lues, which are just integers.
> --
> http:/= /mail.python.org/mailman/listinfo/python-list

KeyError: 1 means that there is no int(1) key. I think you m= eant to do "for key in sorted(yourdict.keys())"

--e89a8f50389ccdec9104dec9622a--