<分区> 分区>
我有一个 python 字典:
aDict = {
'form-1-device': ['2'],
'form-0-test_group': ['1'],
'form-1-test_scenario': ['3'],
}
我需要从 dict 中删除 form-1-device 和 device 等等。到目前为止,我已经试过了:
for k,v in bDict.iteritems():
newk = [k[k.find('-',5)+1:]]
print newk
aDict[newk] = aDict[k]
del aDict[k]
或代替
aDict[newk] = aDict[k]
del aDict[k]
这也能完成工作
aDict[newk] = aDict.pop(k)
我的预期输出是:
aDict = {
'device': ['2'],
'test_group': ['1'],
'test_scenario': ['3'],
}
但它给出了一个错误 TypeError: unhashable type: 'list' in python dict 到目前为止,我查看了 Python dictionary : TypeError: unhashable type: 'list'和 Python, TypeError: unhashable type: 'list' 也看过这个Python creating dictionary key from a list of items 但对我没有任何作用。任何帮助将不胜感激。
