[英]TypeError: 'tuple' object does not support item assignment in dictionary
無法對字典元素的相應值進行遞增
sentiment_words = {}
for word in TotalVector:
if not word in sentiment_words:
sentiment_words[word]=(0,0,0)
#sentiment_word(positive,negative,neutral)
if ispositive(word):
sentiment_words[word][0] += 1
elif isnegative(word):
sentiment_words[word][1] += 1
elif isneutral(word):
sentiment_words[word][2] += 1
print sentiment_words
Python tuples
是不可變的。 請改用list
。 喜歡:
sentiment_words[word]=[0,0,0]
然后轉換為元組:
sentiment_words = tuple(sentiment_words)
聲明:本站的技術帖子網頁,遵循CC BY-SA 4.0協議,如果您需要轉載,請注明本站網址或者原文地址。任何問題請咨詢:yoyou2525@163.com.