2
如果我有一個列表和一個函數來計算分數,我可以計算argmax這樣:什麼是計算argmax的pythonic方法?
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方式這樣做?
好得多,我沒有看過他的代碼足夠接近:P –