[lang-ref] ( array_max_value_by_key ) ( python )
def test_array_max_value_by_key():
# max(score for ..)
items = [
{ 'name': 'A', 'score': 30 },
{ 'name': 'B', 'score': 40 },
{ 'name': 'C', 'score': 80 },
{ 'name': 'D', 'score': 20 },
{ 'name': 'E', 'score': 90 },
{ 'name': 'F', 'score': 10 },
]
top_score1 = max(x['score'] for x in items) # generator (preferred: no extra list)
top_score2 = max([x['score'] for x in items]) # list comprehension
assert top_score1 == 90
assert top_score2 == 90