I want to sort a dictionary on the basis of values while keeping the keys in the mind also. I want the keys to be in the order that I want (the keys should be in reverse sorted fashion for same values), but by default the keys are in sorted fashion for same values. How would I do that?
dictionary = {'t':1, 'p':1, 'r':1, 'o':2, 'a':1}
dictonary = sorted(dictonary.items(), key=itemgetter(1,0))
I get something like this. ('o', 2) ('t', 1) ('r', 1) ('p', 1) ('a', 1) but I want ('t', 1) ('r', 1) ('p', 1) ('a', 1) ('o', 2) that is for same values sort it reversely for same values.