Sorting a set works, sorting a dictionary fails ?

Νικόλαος Κούρας nikos.gr33k at gmail.com
Mon Jun 10 05:48:43 EDT 2013


After many tried this did the job:

for key in sorted(months.items(),key=lambda num : num[1]):
	print('''
		<option value="%s"> %s </option>
	''' % (key[1], key[0]) )


but its really frustrating not being able to:

for key in sorted( months.values() ): 
        print(''' 
                <option value="%s"> %s </option> 
        ''' % (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?



More information about the Python-list mailing list