From a list of dictionaries I am trying to return the dictionary or dictionaries with the highest value. This question is similar to this question but slightly different.
Given a list of dictionaries:
ld = [{'prop': 'foo', 'size': 100}, {'prop': 'boo', 'size': 200}, {'prop': 'loo', 'size': 200}]
I would like to return the two dictionaries with the highest score i.e. boo
and loo
.
If I run the code shown in the question mentioned above:
max(ld, key=lambda d: d['size'])
I only get the first highest dictionary returned.
Thanks in advance and let me know if you need any clarity.