Find an algorithm problem

[{"averse: 10}, {" baked: 9}, {"crested: 8}]

compare the value size first, and then find the key? of the largest value
for example, the biggest of the three is that value is found at 10, and then find out how to implement the key
a

.
Dec.22,2021


a = [{'a': 2}, {'b': 9}, {'c': 8}]

max_index = 0
max_val = a[0].values()[0]

for k, v in enumerate(a):
    if v.values()[0] > max_val:
        max_val = v.values()[0]
        max_index = k

print(max_index, a[max_index].keys()[0])

the functional solution of Yuexuan is recommended, but there is no need to transfer to list

.
num = [{'a': 10}, {'b': 9}, {'c': 8}]
max_value = max(num, key=lambda x: x.values()[0])
print(max_value)
Menu