python - how to get the index of dictionary with the highest value in a list of dictionary -


i have list of dictionaries, possible dictionary or index has highest score key value? here list.

 lst= [{'name':'tom','score':5},{'name':'jerry','score':10},{'name':'jason','score':8}] 

if should return

{'name':'jerry','score':10} 

thanks.

the built-in function, max() takes optional key function, can supplied in form of lambda:

>>> max(lst, key=lambda x:x['score']) {'score': 10, 'name': 'jerry'} 

Comments

Popular posts from this blog

c# - SharpSVN - How to get the previous revision? -

c++ - Is it possible to compile a VST on linux? -

url - Querystring manipulation of email Address in PHP -