Skip to content

Instantly share code, notes, and snippets.

@nitely
Last active November 29, 2015 19:37
Show Gist options
  • Save nitely/a0775509d983ec47b055 to your computer and use it in GitHub Desktop.
Save nitely/a0775509d983ec47b055 to your computer and use it in GitHub Desktop.
Merge dicts
# Untested
def merge(dict_a, dict_b, **kwargs):
assert isinstance(dict_a, dict), \
"A dict was expected in %s" % kwargs.pop('node_name', 'first param')
for k, v in dict_b.items():
if isinstance(v, dict):
merge(dict_a.setdefault(k, {}), v, node_name=k)
continue
dict_a.setdefault(k, v)
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment