这段代码给我一个错误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) 我正在尝试编写一个Character Generator可以用于笔和纸角色扮演游戏的简单脚本。我正在考虑将所有信息存储在嵌套字典中并将其保存到 JSON 文件中。
但是,在创建以下字典时,我收到错误:
nhashable type: 'dict', focussing on {'cha': 1}}}
Run Code Online (Sandbox Code Playgroud)
core_phb = {
'races': {
'Human': {
{'abilities': 'None'},
{'alignment': 'Neutral'},
{'size': 'Medium'},
{'speed': 6},
{'languages': 'Common'},
{'ability_modifiers': {
{'str': 1},
{'dex': 1},
{'con': 1},
{'int': 1},
{'wis': 1},
{'cha': 1}}}
},
'Dwarf': {
{'abilities': [
'ability1',
'ability2'
]},
{'alignment': 'Lawful Good'},
{'size': 'Medium'},
{'speed': 5},
{'languages': [
'Common',
'Dwarven'
]},
{'ability_modifiers': [
{'con': 2},
{'wis': 1}
]}
},
'Elf': {
{'abilities': [
'ability1',
'ability2'
]}, …Run Code Online (Sandbox Code Playgroud)