TypeError: unhashable type: 'list' for text summarization

85 Views Asked by At
from nltk.corpus import indian

sentence_score={}
#word=nltk.word_tokenize(text)
for sent in sentences:
    word_count_in_sentence = (len(nltk.word_tokenize(sentence)))
    if word in wordfreq.keys():
        if sent not in sentence_score.keys():
            sentence_score[sent]=wordfreq[word]
        else:
            senetence_score[sent]+=wordfreq[word]

I m getting this error what do i do

TypeError: unhashable type: 'list' for line 7 i.e    if word in wordfreq.keys():
1

There are 1 best solutions below

0
On BEST ANSWER

Use a defaultdict

from nltk.corpus import indian
from collections import defaultdict

sentence_score=defaultdict(int)
#word=nltk.word_tokenize(text)
for sent in sentences:
    word_count_in_sentence = (len(nltk.word_tokenize(sentence)))
    if word in wordfreq:
        senetence_score[sent]+=wordfreq[word]