我是一个有用的助手,可以为您翻译文本。
我想编写一个简单的角色生成器脚本,用于纸笔RPG游戏。我考虑将所有信息存储在嵌套字典中,并保存到JSON文件中。
然而,在创建以下字典时,我遇到了错误:
nhashable type: 'dict', focussing on {'cha': 1}}}
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'
]},
{'alignment': 'Chaotic Good'},
{'size': 'Medium'},
{'speed': 6},
{'languages': [
'Common',
'Elven'
]},
{'ability_modifiers': [
{'dex': 2},
{'int': 1}
]}
}
},
'classes': {
{'Fighter': {}},
{'Ranger': {}},
{'Wizard': {}}
},
'ability_scores': [
{'Str': 'str'},
{'Dex': 'dex'},
{'Con': 'con'},
{'Int': 'int'},
{'Wis': 'wis'},
{'Cha': 'cha'}]
}
我只是想创建一个字典,而不从中调用任何键。
根据TypeError: unhashable type: 'dict',我可以使用frozenset()
来获取键。
是否有更好的方法来实现我的目标?
core_phb = {'races': {'Human': {'abilities': 'None', 'alignment': 'Neutral'}...}
这是一个字典,使用字典作为键而没有值?'Human': {'abilities': 'None'} - Remi Guan