TypeError:“tuple”对象不支持字典中的项分配

2024-10-02 08:29:55 发布

您现在位置:Python中文网/ 问答频道 /正文

无法对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

Tags: in元素fordictionaryifnot增量word

热门问题