I have the following dictionary.
var = a = { \'Black\': { \'grams\': 1906, \'price\': 2.05}, \'Blue\': { \'grams\': 9526, \'price\': 22.88}, \'Gold\':
Construct an OrderedDict from a list of ordered item tuples:
OrderedDict
from collections import OrderedDict ordered = OrderedDict(sorted(a.items(), key=lambda i: i[1]['price']))
(.items() assumes Python 3, in Python 2 iteritems should do the same.)
.items()
iteritems