我有一个输入文件,其中每一行都有一组单词。接下来,我进行查询并计算输入文件的每一行与查询之间的相似度分数。我试图通过使用字典来做到这一点,将字典的最大大小保持为 20(如果按值排序,则获得前 20 个结果)但我收到以下语法错误:
File "retrieve.py", line 47
result.item()[20].key()=temp
SyntaxError: can't assign to function call
我的代码是:
images=open("jcnout","r")
res=open("result","w")
while linecount>0: //linecount is the num of lines in file images
line=images.readline().split()
////compute score for each line
if (len(result)<20):
result[str(line)]=score
else:
if(len(result)==20):
result = sorted(result.iteritems(), key=operator.itemgetter(1))
if(result.item()[20].value()<score):
result.item()[20].key()=str(line)
result.item()[20].value=score
result = sorted(result.iteritems(), key=operator.itemgetter(1))
res.write(result)
linecount-=1