【发布时间】:2021-04-26 02:31:12
【问题描述】:
我有一个包含字典列表的字典列表:
super_data: [{'data': [{'attributes': {'stuff': 'test'
'stuff2': 'tester'}
}]}
{'data': [{'attributes': {'stuff': 'test2'
'stuff2': 'tester2'}
}]}
我还有其他字典列表,可能看起来像:
super_meta_data: [{'meta_data': [{'attributes': {'thing': 'testy'
'thing2': 'testy2'}
}]}
{'meta_data': [{'attributes': {'thing': 'testy3'
'thing': 'testy4'}
}]}
我想像这样合并嵌套的字典列表:
super_data: [{'data': [{'attributes': {'stuff': 'test'
'stuff2': 'tester'}
}]
'meta_data': [{'attributes': {'thing': 'testy'
'thing2': 'testy2'}
}]
}
{'data': [{'attributes': {'stuff': 'test'
'stuff2': 'tester'}
}]
'meta_data': [{'attributes': {'thing': 'testy3'
'thing2': 'testy4'}
}]
}
我该怎么做呢?我正在尝试:
for i in super_data:
super_data.append([i][super_meta_data]
但它正在抛出:
TypeError: 列表索引必须是整数或切片,而不是字典
欣赏任何见解!
【问题讨论】:
-
请发布帮助者可以复制和粘贴的实际 Python 数据结构。让他们猜测和虚假输入是不体贴的。
标签: python json python-3.x python-2.7 dictionary