I want to sort this dictionary d based on value of sub key key3 in descending order. See below:
d = { '123': { 'key1': 3, 'key2': 11, 'key3': 3 },
'124': { 'key1': 6, 'key2': 56, 'key3': 6 },
'125': { 'key1': 7, 'key2': 44, 'key3': 9 },
}
So final dictionary would look like this.
d = { '125': { 'key1': 7, 'key2': 44, 'key3': 9 },
'124': { 'key1': 6, 'key2': 56, 'key3': 6 },
'123': { 'key1': 3, 'key2': 11, 'key3': 3 },
}
My approach was to form another dictionary e from d, whose key would be value of key3 and then use reversed(sorted(e)) but since value of key3 can be same, so dictionary e lost some of the keys and their values. makes sense?
How I can accomplish this? This is not a tested code. I am just trying to understand the logic.