Hey I am trying to sort a dictionary by value from highest to lowest value. Howevet I want the items with same values to be sorted by key.
The following code does not work
dictionary = {"Sophie": 23, "Alfred": 23, "Zelda":22, "Betty":23}
sorted(dictionary.items(), key=lambda t: t[::-1])
Output:
[('Zelda', 22), ('Alfred', 23), ('Betty', 23), ('Sophie', 23)]
Expected output:
[('Alfred', 23), ('Betty', 23), ('Sophie', 23), ('Zelda', 22)]
ordered by decreasing value, then by key (alphabetical)