Ordered Dict:
import collections d = {\'banana\': 3, \'apple\':4, \'pear\': 1, \'orange\': 2} collections.OrderedDict(sorted(d.items(), key=lamb
Once you initialized regular dict with your items the order is gone. So just initialize ordered dict in initial order:
import collections as co co.OrderedDict([(a, b) for a, b in list_of_pairs]) # or d = co.OrderedDict() for a, b in list_of_pairs: d[a] = b