Created
December 29, 2010 07:03
-
-
Save adeel/758288 to your computer and use it in GitHub Desktop.
Like dict.update, but recursive.
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 _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