I have a dictionary in the format given below. I want to sort the dictionary based on the value of the "score" values in decreasing order, and in case of a tie, sort in lexicographical order of the "title" value.
d = {
'123':{
'score': 100,
'title': 'xyz'
},
'234':{
'score': 50,
'title': 'abcd'
},
'567':{
'score': 50,
'title': 'aaa'
}
}
So the output should be:
[(100,xyz), (50,aaa), (50,abcd)]
I have tried this:
print sorted(d.items(), key=lambda x: (x[1]['score'], x[1]['title']), reverse=True)
But it is sorting in decreasing order for both fields.