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

-- 
http://mail.python.org/mailman/listinfo/python-list

Reply via email to