[Solved] Python: Sort dictionary by value (equal values)
dictionaries are unordered (well pre 3.6 at least), instead sort the items d = {3: ‘__init__’, 5: ‘other’, 7: ‘hey ‘, 11: ‘hey’} print(sorted(d.items(),key=lambda item:(item[0].strip(),item[1]))) # output => [(3, ‘__init__’), (7, ‘hey ‘), (11, ‘hey’), (5, ‘other’)] if you really want it as a dict (for reasons i cant fathom) and you are using 3.6+ … Read more