d = {'banana': 3, 'apple': 4, 'pear': 1, 'orange': 2}
OrderedDict(sorted(list(d.items()), key=lambda t: t[0]))
OrderedDict(sorted(list(d.items()), key=lambda t: t[1]))
Sorting alphanumerical dictionary keys in python