The problem of finding an algorithm

[{"averse: 123123123}, {" baked: 123123123}, {"crested: 231212}]

find out the one with the largest value, and then find out how that key writes the algorithm through the largest value-sharp-sharp-sharp topic description

Dec.13,2021

traversal

cycle pairwise comparison, record the larger value and the corresponding key, to the end, and then record the value and key is the largest


an idea: with reference to bubble sorting, you can filter out the maximum or minimum values in just one traversal. Take the head or tail to get the maximum or minimum item. If there are multiple items with the same value, they must also be concentrated at both ends.


In [20]: a=[{'a': 123123123}, {'b': 123123123}, {'c': 231212}]

In [21]: max(a, key=lambda d:list(d.values())[0])
Out[21]: {'a': 123123123}

In [22]: list(max(a, key=lambda d:list(d.values())[0]).keys())[0]
Out[22]: 'a'
Menu