我是Python的新手,这可能已经得到了回答,但是我找不到一个类似的问题,这个问题将涉及合并多字典词典。
所以我的问题是:如何合并dict1
和dict2
以dict3
结尾,如下所示?
感谢您的时间和帮助!
#inputs
dict1 = {'aapl':
{'Cash & Cash Equivalents':
{'2017': 74181,
'2016': 67155},
'Receivables':
{'2017': 29299,
'2016': 30343}},
'nvda':
{'Cash & Cash Equivalents':
{'2017': 7108,
'2016': 6798},
'Receivables':
{'2017': 826,
'2016': 505}}
}
dict2 = {'aapl':
{'Income Tax':
{'2017': 41181,
'2016': 12355},
'After-Tax Income':
{'2017': 22323,
'2016': 12345}},
'nvda':
{'Income Tax':
{'2017': 1209,
'2016': 1192},
'After-Tax Income':
{'2017': 12326,
'2016': 11093}}
}
#output
dict3 = {'aapl':
{'Cash & Cash Equivalents':
{'2017': 74181,
'2016': 67155},
'Receivables':
{'2017': 29299,
'2016': 30343},
'Income Tax':
{'2017': 41181,
'2016': 12355},
'After-Tax Income':
{'2017': 22323,
'2016': 12345}},
'nvda':
{'Cash & Cash Equivalents':
{'2017': 7108,
'2016': 6798},
'Receivables':
{'2017': 826,
'2016': 505},
'Income Tax':
{'2017': 1209,
'2016': 1192},
'After-Tax Income':
{'2017': 12326,
'2016': 11093}}
}