I have a dict that looks like this:
{0: 2, 1: 4, 2: 2, 3: 2, 4: 5}
That is, both the keys and values integers.
I need to sort this dict in this way:
- By the value first, ascending;
- by the key, if the values ties, descending.
All I know is that python's sorted() function supports a parameter called "key" but it seems that it just allows to have either key or value at once.
What can I do to achieve?
FYI, the result should be like:
{2: 2, 0: 2, 3: 2, 1: 4, 4: 5}