更新不同深度的嵌套字典的值
我正在寻找一种方法来更新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}}}
我知道更新会删除level2中的值,因为它正在更新最低密钥level1。
鉴于dictionary1和update可以有任何长度,我怎么能解决这个问题呢?
浮云间
慕婉清6462132
偶然的你
相关分类