Dictionaries again - where do I make a mistake?
Lad
python at hope.cz
Thu Oct 19 11:39:36 EDT 2006
I use the following code to sort dictionary.
Olddict={'r':4,'c':1,'d':2,'e':3,'f':2}
Newdict={}
i = [(val, key) for (key, val) in Olddict.items()]
i.sort() # by val
i.reverse() # Get largest first.
for (val, key) in i:
print key,val
Newdict[key]=val
print Olddict
print Newdict
Sorting seems to be OK,.
the command
print key,val
prints the proper values
but I can not create Newdict to be sorted properly.
Where do I make a mistake?
Thank you for help.
L
More information about the Python-list
mailing list