Created
May 26, 2018 21:02
-
-
Save skylerberg/895da7e71e2ea91c2f5e56fd0ad6125e to your computer and use it in GitHub Desktop.
Patch
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 merge_patch(target, patch): | |
if isinstance(patch, dict): | |
if not isinstance(target, dict): | |
target = {} | |
for name, value in patch.iteritems(): | |
if value is None: | |
if name in target: | |
del target[name] | |
else: | |
target[name] = merge_patch(target[name], value) | |
return target | |
else: | |
return patch |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment