Possible Duplicate:
Sort by key of dictionary inside a dictionary in Python
I have a dictionary:
d={'abc.py':{'map':'someMap','distance':11},
'x.jpg':{'map':'aMap','distance':2},....}
Now what I need is: I need to sort d according to their distances?
I tried sorted(d.items(),key=itemgetter(1,2), but it’s not working.
How can it be done?
A dictonary can’t be sorted. So you have to convert your data to a list and sort this list.
Maybe you convert your dict to a list of tuples (key, value) and sort then.