I would like to deep-merge 2 dictionaries which both have at some level one or more dictionaries values with the same key. How can I merge also those internal dictionaries simply? Something like the "**" notation but a deep merge.
Example:
d1 = {"v1": "value1", "sub": {"sv1": "sub value 1"}}
d2 = {"v2": "value2", "sub": {"sv2": "sub value 2"}}
d3 = {**d1, **d2}
print(d3)
Actual result:
{'v1': 'value1', 'sub': {'sv2': 'sub value 2'}, 'v2': 'value2'}
Desired result:
{'v1': 'value1',
'sub': {'sv1': 'sub value 1', 'sv2': 'sub value 2'},
'v2': 'value2'}
Noticed the sub -> sv1 -> sub value 1
This is a simple example while the real case have several more levels of dictionaries. Moreover the solution needs to be generic since the structure of the dictionaries is not known in advanced.