could someone help me select the minimum value between two keys? For example, if I have the list of dictionaries:
results = [
{
"model": "short",
"score": 34,
"alt_score": 1
},
{
"model": "med",
"score": 22,
"alt_score": 11
},
{
"model": "tall",
"score": 42,
"alt_score": 90
},
{
"model": "xtall",
"score": 83,
"alt_score": 15
},
]
I want to select the dictionary that has the smallest score OR alt_score. I know how to find the dictionary w/ the smallest score or alt_score individually:
min(results, key=lambda x:x['alt_score'])
but I'm not sure how to look at two keys at once. I would need something like:
min(results, key=lambda x:x['score', 'alt_score])
or
min(results, key=lambda x:x['score'] or x:x['alt_score'])
the result should return:
{
"model": "short",
"score": 34,
"alt_score": 1
}
Thanks in advance!