我正在寻找一种方法来更新dict dictionary1与dict更新的内容wihout覆盖levelA
dictionary1={'level1':{'level2':{'levelA':0,'levelB':1}}}
update={'level1':{'level2':{'levelB':10}}}
dictionary1.update(update)
print dictionary1
{'level1': {'level2': {'levelB': 10}}}
Run Code Online (Sandbox Code Playgroud)
我知道更新会删除level2中的值,因为它正在更新最低密钥level1.
鉴于dictionary1和update可以有任何长度,我怎么能解决这个问题呢?
python ×1