I need to sort this dict with two sequential criteria: "rank" descending, "fruit" ascending (in case of same ranking result).
The dict is structured in this way
'object':['fruit',rank]
For example I've:
myDict = {'item2': ['bananas', 3], 'item3': ['cocumbers', 11], 'item1': ['pinapples', 3], 'item4': ['pears', 3]}
My aim is to obtain this:
{'item3': ['cocumbers', 11], 'item2': ['bananas', 3],'item4': ['pears', 3], 'item1': ['pinapples', 3]}
with
sorted(myDict.items(), key=lambda (k, v): v[1], reverse=True)
I obtain only the correct sorting for rank but with no sorting order for the objects with the same ranking:
[('item3', ['cocumbers', 11]), ('item2', ['bananas', 3]), ('item1', ['pinapples', 3]), ('item4', ['pears', 3])]
How solve this in python 2.7?
Thank's