python - TypeError: unhashable type: 'list' 用于文本摘要
问题描述
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]
我收到此错误我该怎么办
TypeError: unhashable type: 'list' for line 7 i.e if word in wordfreq.keys():
解决方案
用一个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]
推荐阅读
- javascript - 我无法遍历对象数组
- node.js - 当Heroku中的product = firefox时Puppeteer不工作
- azure - 什么是无头身份验证?
- python - 我如何使用谷歌浏览器而不是 Chromedriver Python Selenium
- java - 序列化时杰克逊 InvalidDefinitionException
- hadoop - 如何实现自定义委托令牌
- docker - alpine docker 映像中 chrooted ssh 中的 Rsync 导致设置权限失败
- flutter - 如何让flutter appbar显示手机的时钟和网络
- python - Python DataFrame Filtering and Sorting at the Same Time
- node.js - 在 moongose 中,如果我正在创建一个包含 4 个字段的架构。但我只保存两个字段的值。如何更新未给出的字段值?