for k, v2 in list(d2.items()):
    v1 = d1.get(k)
if isinstance(v1, collections.Mapping) and isinstance(v2, collections.Mapping):
    merge_dict(v1, v2)
else:
    d1[k] = v2
Python, merge multi-level dictionaries