像这样的东西?
>>> a = [('123c', 0.0), ('123c1', 0.0), ('123c2', 0.10456917162915072), ('123c3', 0.097595441008939465), ('123c4', 0.0), ('12c35', 0.0), ('13836', 0.040490933063262943)]
>>> max(a, key = lambda x: x[1]) # Or max(a, key = itemgetter(1))
('123c2', 0.10456917162915072)
>>> max(a, key = lambda x: x[1])[0]
'123c2'
关于max()
功能,
max(...)
max(iterable[, key=func]) -> value
max(a, b, c, ...[, key=func]) -> value
With a single iterable argument, return its largest item.
With two or more arguments, return the largest argument.
上例中的第二个参数max(...)
是 key 函数,它让函数决定最大化哪个值。