in this statement
stop_words_index = [word_index.get(w) + 3 for w in stop_words]
word_index.get(w) is an int, but this statement generates
TypeError: unsupported operand type(s) for +: 'NoneType' and 'int'
How to fix this?
in this statement
stop_words_index = [word_index.get(w) + 3 for w in stop_words]
word_index.get(w) is an int, but this statement generates
TypeError: unsupported operand type(s) for +: 'NoneType' and 'int'
How to fix this?
word_index.get(w)isNoneifwcannot be found in dictionnaryword_index.You should do
word_index.get(w, 0)if you want this value to be 0 whenwis not found.Or
[word_index.get(w) + 3 for w in stop_words if w in word_index]if you want to skip the not found words.