【发布时间】:2020-06-12 07:08:16
【问题描述】:
我有一个场景,我有以下 json 数据
data = {
"app": [
{
"ida": 10,
"configur": {
"config": [
{
"active": "true",
"tol": "id"
}
]
}
},
{
"ida": 11,
"configur": {
"config": [
{
"active": "true",
"tol": "id"
}
]
}
}, {
"ida": 11,
"configur": {
"config": [
{
"active": "true",
"tol": "id"
}
]
}
}
]
}
这里我想将每个元素中的tol 值替换为ida
这是我的代码:
data3 = []
for cmpkey2 in data['app']:
spcmpg = cmpkey2['configur']['config']
tempev = cmpkey2['ida']
for key34 in spcmpg:
key34['tol'] = tempev
data3.append({ "ida": tempev, "config": spcmpg})
这里的新字典 data3 没有用 ida 值替换 tol 值,我在哪里做错了?
任何帮助都会很棒!
【问题讨论】:
标签: python json python-3.x list