Skip to content

Instantly share code, notes, and snippets.

@adeel
Created December 29, 2010 07:03
Show Gist options
  • Save adeel/758288 to your computer and use it in GitHub Desktop.
Save adeel/758288 to your computer and use it in GitHub Desktop.
Like dict.update, but recursive.
def _recursive_dict_update(x, y):
for key, val in y.iteritems():
if isinstance(val, dict):
if not x.has_key(key):
x[key] = {}
x[key] = _recursive_dict_update(x[key], val)
elif isinstance(val, list):
if not x.has_key(key):
x[key] = []
x[key].extend(val)
else:
x[key] = val
return x
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment