好的,我有这个简单的函数,它可以找到列表中使另一个正函数的值最大化的元素。
def get_max(f, s):
# f is a function and s is an iterable
best = None
best_value = -1
for element in s:
this_value = f(element)
if this_value > best_value:
best = element
best_value = this_value
return best
但我发现它所做的简单工作很长。事实上,它让我想起了 Java (brrrr)。任何人都可以向我展示一种更pythonic和更干净的方式吗?
谢谢!
曼努埃尔