如果我有一个列表和一个函数来计算分数,我可以这样计算 argmax:
maxscore = 0; argmax = None
x = [3.49, 0.122, 293, 0.98] # Imagine a LARGE list.
for i in x:
# Maybe there're some other func() to calculate score
# For now just sum the digits in i.
score = sum([int(j) for j in str(i) if j.isdigit()])
print i, score
if maxscore < score:
maxscore = score
argmax = i
有没有其他方法可以实现 argmax?这样做的pythonic方法是什么?