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


Groups > comp.lang.python > #46066

Re: Error when trying to sort and presnt a dictionary in python 3.3.1

From Peter Otten <__peter__@web.de>
Subject Re: Error when trying to sort and presnt a dictionary in python 3.3.1
Date 2013-05-26 14:20 +0200
Organization None
References <95e674bf-0d96-479c-b7a4-9242768a7a46@googlegroups.com>
Newsgroups comp.lang.python
Message-ID <mailman.2172.1369570798.3114.python-list@python.org> (permalink)

Show all headers | View raw


Νίκος Γκρ33κ wrote:

> python3 pelatologio.py gives  me error in this line:
> 
> Traceback (most recent call last):
>   File "pelatologio.py", line 283, in &lt;module&gt;
>     ''' % (months[key], key) )
> KeyError: 1
> 
> The code is:
> 
> #populating months into a dropdown menu
> years = ( 2010, 2011, 2012, 2013 )
> months = { 'Ιανουάριος':1, 'Φεβρουάριος':2, 'Μάρτιος':3, 'Απρίλιος':4,
> 'Μάϊος':5, 'Ιούνιος':6, \ 'Ιούλιος':7, 'Αύγουστος':8, 'Σεπτέμβριος':9,
> 'Οκτώβριος':10, 'Νοέμβριος':11, 'Δεκέμβριος':12 }

You have keys and values mixed up...
 
> print('''
> <form method="post" action="">
> <select name="month">
> ''')
> 
> for key in sorted( months.values() ):

and calling the value key doesn't help there.

> print('''
> <option value="%s"> %s </option>
> ''' % (months[key], key) )

At some point you have to admit that coding isn't your cup of tea.
Or Ouzo ;(

Back to comp.lang.python | Previous | NextPrevious in thread | Next in thread | Find similar | Unroll thread


Thread

Error when trying to sort and presnt a dictionary in python 3.3.1 Νίκος Γκρ33κ <nikos.gr33k@gmail.com> - 2013-05-26 04:11 -0700
  Re: Error when trying to sort and presnt a dictionary in python 3.3.1 Peter Otten <__peter__@web.de> - 2013-05-26 14:20 +0200
    Re: Error when trying to sort and presnt a dictionary in python 3.3.1 Νίκος Γκρ33κ <nikos.gr33k@gmail.com> - 2013-05-26 05:58 -0700
      Re: Error when trying to sort and presnt a dictionary in python 3.3.1 Νίκος Γκρ33κ <nikos.gr33k@gmail.com> - 2013-05-26 09:09 -0700

csiph-web