相关疑难解决方法(0)

TypeError:不可用类型:'dict'

这段代码给我一个错误unhashable type: dict,任何人都可以解释我的解决方案是什么

negids = movie_reviews.fileids('neg')
def word_feats(words):
    return dict([(word, True) for word in words])

negfeats = [(word_feats(movie_reviews.words(fileids=[f])), 'neg') for f in negids]
stopset = set(stopwords.words('english'))

def stopword_filtered_word_feats(words):
    return dict([(word, True) for word in words if word not in stopset])

result=stopword_filtered_word_feats(negfeats)
Run Code Online (Sandbox Code Playgroud)

python

144
推荐指数
3
解决办法
24万
查看次数

TypeError:unhashable type:'dict',当dict用作另一个dict的键时

我有这段代码:

for element in json[referenceElement].keys():
Run Code Online (Sandbox Code Playgroud)

当我运行该代码时,我收到此错误:

TypeError:不可用类型:'dict'

导致该错误的原因是什么,我该怎么做才能解决?

python hash json

63
推荐指数
1
解决办法
15万
查看次数

标签 统计

python ×2

hash ×1

json ×1