无法对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
。比如:然后转换为元组:
^{pr2}$相关问题 更多 >
编程相关推荐