def deep_merge_dict(a, b):
"""Deep merges dictionary b into dictionary a."""
_a = copy(a)
_b = copy(b)
for key_b, val_b in iteritems(_b):
# if it's a sub-dictionary
if isinstance(val_b, dict):
if key_b not in _a or not isinstance(_a[key_b], dict):
_a[key_b] = {}
# perform the deep merge recursively
_a[key_b] = deep_merge_dict(_a[key_b], val_b)
else:
_a[key_b] = val_b
# b should now be deep-merged into a
return _a
评论列表
文章目录