sorting - Sort a Python dictionary by value - Stack Overflow
In recent Python 2.7, we have the new OrderedDict type, which remembers the order in which the items were added. >>> d = {"third": 3, "first": 1, "fourth": 4, "second": 2} >>> for k, v in d.items(): ... print "%s: %s" % (k, v) ... second: 2 fourth: 4 thir...