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

Νίκος Γκρ33κ nikos.gr33k at gmail.com
Sun May 26 07:11:56 EDT 2013


python3 pelatologio.py gives  me error in this line:

Traceback (most recent call last):
  File "pelatologio.py", line 283, in <module>
    ''' % (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 }

print('''
<form method="post" action="">
	<select name="month">
''')
	
for key in sorted( months.values() ):
	print('''
		<option value="%s"> %s </option>
	''' % (months[key], key) )



More information about the Python-list mailing list