How to sort OrderedDict
I want to sort a dict by values and then if values are equal, then sort by alphabetic key:
od=OrderedDict(sorted(zhanr.items(),key=lambda x:x[1],reverse=True))
I tried this code for values but don't know how to sort by the key if the values are equal.
i think this would work for you:
sorted(dictionary.items(), key=lambda t: t[::-1])
which is the same as:
def reverse_tuple(t):
return t[::-1]
sorted(dictionary.items(), key=reverse_tuple)