Get dict from list of dicts with the maximum of two items

I would like to get the dict in a list of dicts which has the maximum of two values:


I want to select the managers that have the latest start date, then get the manager with the max value of perc

I can do:

max(managers, key=lambda x:x['perc'])

to get the maximum perc, how to i do get it to return more than one dict. In this case it gives manager3. But I want manager4 returned.

>Solution :

You can just create a tuple of your max keys by relevance:

max(managers, key=lambda x:(x['start_date'], x['perc']))

Leave a Reply