I have this dictionary:
Dict = {'Key1': ['LONG', 1], 'Key3': ['LONG', 7], 'Key4': ['LONG_A', 9]}
Each value of the dictionary contains a tuple with a string and an int value. I would like to sort this dictionary by the int value (in descending order).
The result should be:
Expected = {'Key4': ['LONG_A', 9],'Key3': ['LONG', 7],'Key1': ['LONG', 1]}
Sorted in python
Use this code:
sorted(Dict.items(), key=lambda x: x[1][1],reverse=True)
Output:
[('Key4', ['LONG_A', 9]), ('Key3', ['LONG', 7]), ('Key1', ['LONG', 1])]
2.1m questions
2.1m answers
60 comments
57.0k users