This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
def deep_merge(dict1: dict, dict2: dict) -> dict: | |
""" Merges two dicts. If keys are conflicting, dict2 is preferred. """ | |
def _val(v1, v2): | |
if isinstance(v1, dict) and isinstance(v2, dict): | |
return deep_merge(v1, v2) | |
return v2 or v1 | |
return {k: _val(dict1.get(k), dict2.get(k)) for k in dict1.keys() | dict2.keys()} |