I have a list of dictionary like below,
x = [
{"matches_count": 10, distance: 50},
{"matches_count": 20, distance: 50},
{"matches_count": 1, "distance: 20},
{"matches_count": 2, "distance": 20},
{"matches_count": 5, "distance: 30},
]
I need to sort this like below
x = [
{"matches_count": 2, distance: 20},
{"matches_count": 1, "distance: 20},
{"matches_count": 5, "distance: 30},
{"matches_count": 20, distance: 50},
{"matches_count": 10, "distance": 50}
]
Basically, this should be sort with both distance and the matches_count. When the distance is the same the highest matches count should come first. Is there any possibility to do this with the sorted method? Or is there any other way to perform this?
I have checked the below questions and I did not able to get proper insight from them for my question. Sort list of dictionaries by multiple keys with different ordering