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