【发布时间】:2021-08-04 19:19:25
【问题描述】:
我有 2 个嵌套字典:
grouped1 ={'LabelStat': { 'Carrier': ['1', '1'],
'FormID': ['0201', '0430']},
'McAfee': {'DatDate': 'Not Available',
' DatVersion': 'Not Available'}
}
grouped2 ={'LabelStat': {'Carrier': ['2', '2'],
'FormID': ['10201', '10430']},
'McAfee': {'DatDate': 'Available',
'DatVersion': 'Available',}
}
我想附加这两个字典,输出应该是这样的:
com_grouped = {
'LabelStat': {'Carrier': ['1', '1','2','2'],
'FormID': ['0201', '0430','10201', '10430']}
'McAfee': {'DatDate': ['Not Available','Available']
'DatVersion': ['Not Available','Available']}
}
第一次尝试:
com_grouped = grouped1.update(grouped2)
print(com_grouped)
而且没有输出。
然后我累了:
com_grouped = grouped1
com_grouped=com_grouped.update(grouped2)
print(com_grouped)
输出还是没有!
【问题讨论】:
-
使用嵌套循环。
-
StackOverflow 不是免费的编码服务。你应该try to solve the problem first。请更新您的问题以在minimal reproducible example 中显示您已经尝试过的内容。如需更多信息,请参阅How to Ask,并拨打tour :)
-
是的,先生,我同意你的看法,会更新,谢谢你的提醒!
-
嗨@Barmar,我刚刚编辑了我的问题,请给我一些建议,非常感谢!
标签: python python-3.x dictionary nested python-3.5