utils.py 文件源码

python
阅读 18 收藏 0 点赞 0 评论 0

项目:statik 作者: thanethomson 项目源码 文件源码
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
评论列表
文章目录


问题


面经


文章

微信
公众号

扫码关注公众号