0
我目前有兩個字典。我想採用包含更多鍵 - 值對的第二個字典,並將字典值附加到第一個字典中的值。如何將兩個字典作爲值(二級字典)結合使用
Dictionary1 = {'47289': {'totcount': 5.0, 'totunits': 89.8},
'18109': {'totcount': 82.92, 'totunits': 829.67}}
Dictionary2 = {'47289': {'average': 927.90, 'median': 288.8},
'18109': {'average': 927.92, 'median': 3728.97},
'92738': {'average': 729.91, 'median': 472.88}}
Result = {'47289': {'totcount': 5.0, 'totunits': 89.8, 'average': 927.90, 'median': 288.8},
'18109': {'totcount': 82.92, 'totunits': 829.67, 'average': 927.92, 'median': 3728.97}}
,當我嘗試使用Python update()
功能:
Dictionary1.update(Dictionary2)
結果是第一個字典,第二庫值和第一字典中的值已被刪除。
Dictionary1 = {'47289': {'average': 927.90, 'median': 288.8},
'18109': {'average': 927.92, 'median': 3728.97}}
不完全是。 OP想要合併二級字典。 – DyZ