mirror of
https://github.com/open-metadata/OpenMetadata.git
synced 2025-07-10 02:28:22 +00:00
24 lines
799 B
Python
24 lines
799 B
Python
![]() |
def merge(source: dict, destination: dict):
|
||
|
"""
|
||
|
Merge source dictionary into destination dictionary recursively in place.
|
||
|
|
||
|
Examples
|
||
|
# >>> a = { 'first' : { 'all_rows' : { 'pass' : 'dog', 'number' : '1' } } }
|
||
|
# >>> b = { 'first' : { 'all_rows' : { 'fail' : 'cat', 'number' : '5' } } }
|
||
|
# >>> merge(b, a) == { 'first' : { 'all_rows' : { 'pass' : 'dog', 'fail' : 'cat', 'number' : '5' } } }
|
||
|
True
|
||
|
|
||
|
Args:
|
||
|
source (dict): Source dictionary
|
||
|
destination (dict): Destination dictionary
|
||
|
"""
|
||
|
for key, value in source.items():
|
||
|
if isinstance(value, dict):
|
||
|
# get node or create one
|
||
|
node = destination.setdefault(key, {})
|
||
|
merge(value, node)
|
||
|
else:
|
||
|
destination[key] = value
|
||
|
|
||
|
return destination
|