On 10 Jun 2013 09:34, "Νικόλαος Κούρας" <nikos.gr...@gmail.com> wrote: > > Trying this: > > months = { 'Ιανουάριος':1, 'Φεβρουάριος':2, 'Μάρτιος':3, 'Απρίλιος':4, 'Μάϊος':5, 'Ιούνιος':6, \ > 'Ιούλιος':7, 'Αύγουστος':8, 'Σεπτέμβριος':9, 'Οκτώβριος':10, 'Νοέμβριος':11, 'Δεκέμβριος':12 } > > for key in sorted( months.values() ): > print(''' > <option value="%s"> %s </option> > ''' % (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 <module>, 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())"
-- http://mail.python.org/mailman/listinfo/python-list