Sorting a set works, sorting a dictionary fails ?

Steven D'Aprano steve+comp.lang.python at pearwood.info
Mon Jun 10 07:47:37 EDT 2013


On Mon, 10 Jun 2013 03:42:38 -0700, Νικόλαος Κούρας wrote:

> for key in sorted( months.values() ):

> please tell me Uli why this dont work as expected to.

Because values are not keys. You are looking at the values, and trying to 
use them as keys.

months = {'Φεβρουάριος':2, 'Ιανουάριος':1}
print("==Values==")
for x in sorted(months.values()):
    print(x)

print("==Keys==")
for x in sorted(months.keys()):
    print(x)


prints:


==Values==
1
2
==Keys==
Ιανουάριος
Φεβρουάριος



-- 
Steven



More information about the Python-list mailing list