I have the following dictionaries:
mydict1 = {1: 11, 2: 4, 5: 1, 6: 1} mydict2 = {1: 1, 5: 1}
For each of them, I would like to first sort by values ββ(descending), and then by keys (ascending), having received this output:
out_dict1 = [((1, 11), (2, 4), (5, 1), (6, 1)] out_dict2 = [(1, 1), (5, 1)]
How to do it?
I used this, but I can not achieve the result in two cases above:
sorted(mydict.items(), key=lambda x: (x[1],x[0]))
source share