예기치 않은 오류가 발생했습니다. 비슷한 오류가있는 게시물이 있지만 답변을 이해하지 못하거나 내 사례 (사전)와 관련이 없다는 것을 알고 있습니다.python 사전 오류 AttributeError : 'list'객체에 'item'속성이 없습니다.
입력 파일의 각 줄에 대한 유사성 점수를 계산할 때마다 (즉, 입력 파일의 각 줄마다) 반복마다 점수의 상위 20 개 값을 사전에 저장하려고합니다.
result={}
//code for computation of score for each line of an input file
if (len(result)<20):
result[str(line)]=score
else:
if(len(result)==20):
result = sorted(result.iteritems(), key=operator.itemgetter(1))
if(result.item()[19].value()<score):
result.item()[19][str(line)]=score
오류는 다음과 같습니다 :
File "retrieve.py", line 45, in <module>
if(result.item()[19].value()<score):
AttributeError: 'list' object has no attribute 'item'
사전이나 목록에 '항목'방법이 없습니다. –