Created
July 14, 2022 03:24
-
-
Save liweicheng00/ea0cd5e789aa496df676b65417505ef9 to your computer and use it in GitHub Desktop.
Update nest dictionary fro Python
This file contains 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 update(d: dict, u) -> dict: | |
for k, v in u.items(): | |
if isinstance(v, collections.abc.Mapping): | |
d[k] = update(d.get(k, {}), v) | |
else: | |
d[k] = v | |
return d |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment