我的字典的简化:
my_dict = {
'DOC': [
[('k', 'v'), ('k1', 'v1'), ('k2', 'v2'), ('k3', 'v3'), ('k4', 'v4')],
[('k5', 'v5'), ('k', 'v'), ('k1', 'v1'), ('k6', 'v6')]
],
'DIC': [
[('k7', 'v7'), ('k3', 'v3'), ('k8', 'v8')],
[('k5', 'v5'), ('k3', 'v3'), ('k1', 'v1'), ('k2', 'v2')],
[('k4', 'v4'), ('k9', 'v9')]
],
'INFRA': [
[('k5', 'v5'), ('k3', 'v3'), ('k1', 'v1'), ('k2', 'v2')],
[('k', 'v'), ('k1', 'v1'), ('k2', 'v2'), ('k3', 'v3'), ('k4', 'v4')]
]
}
覆盖我的字典值:
for k, v in my_dict.items():
my_dict[k] = map(lambda x: dict(x), my_dict[k])
返回...
my_dict
{'DIC': [{'k3': 'v3', 'k7': 'v7', 'k8': 'v8'},
{'k1': 'v1', 'k2': 'v2', 'k3': 'v3', 'k5': 'v5'},
{'k4': 'v4', 'k9': 'v9'}],
'DOC': [{'k': 'v', 'k1': 'v1', 'k2': 'v2', 'k3': 'v3', 'k4': 'v4'},
{'k': 'v', 'k1': 'v1', 'k5': 'v5', 'k6': 'v6'}],
'INFRA': [{'k1': 'v1', 'k2': 'v2', 'k3': 'v3', 'k5': 'v5'},
{'k': 'v', 'k1': 'v1', 'k2': 'v2', 'k3': 'v3', 'k4': 'v4'}]}
当我按照相同的逻辑运行我的真实代码时,我得到了错误:
ValueError:字典更新序列元素 #0 的长度为 6;2 是必需的
我试图创建另一个字典来接收map()
但发生了同样的错误。有人可以帮助我吗?