這是我試過的。我正在嘗試顯示列表中最高分的文字。但遇到的錯誤:導致錯誤的Python列表排序
for cscore, text in candidates:
score = cscore/len(text)
d = [round(score, 3), ' '.join([u[0] for u in text])]
print d.sort(key = score, reverse=True)[0]
錯誤:
File "example.py", line 47, in <module>
print d.sort(key = score, reverse=True)[0]
NameError: name 'score' is not defined
我candidates
文件是這樣的:https://gist.github.com/JafferWilson/6bdb42c94cab07cce0211582acba12eb
請讓我知道了什麼是可能的方式來獲得最高的文本在列表中評分句子。
什麼關於縮進? – Nabin
請修復您的縮進,併發布'''候選人''看起來像什麼。 – perigon
@ user55449 sure –