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)
MySQL Query : SELECT * FROM `codeshelper`.`v9_news` WHERE status=99 AND catid='6' ORDER BY rand() LIMIT 5
MySQL Error : Disk full (/tmp/#sql-temptable-64f5-1eaaae7-1ff2.MAI); waiting for someone to free some space... (errno: 28 "No space left on device")
MySQL Errno : 1021
Message : Disk full (/tmp/#sql-temptable-64f5-1eaaae7-1ff2.MAI); waiting for someone to free some space... (errno: 28 "No space left on device")
Need Help?