I have the below code base:
import operator
scores = {}
scores[3000] = 18
scores[2000] = 18
scores[1000] = 17
sorted_scores = sorted(scores.items(), key=operator.itemgetter(1),reverse=True)
print (sorted_scores)
This will sort the dictionary scores based on the value. Now what if i want to sort the resultant sorted_scores list based on key , but this time in ascending order.
In other words i am expecting the output to be like this : [(2000, 18),(3000, 18), (1000, 17)]
So this is sorted by values in descending order but since 2000 and 3000 have the same values they are sorted in ascending order.
Can this be achieved in some way?
Thanks in advance.