Module gcip.tools.dict
Functions
def merge_dict(source_dict: Dict[str, Any], target_dict: Dict[str, Any]) ‑> Dict[str, Any]-
Expand source code
def merge_dict( source_dict: Dict[str, Any], target_dict: Dict[str, Any] ) -> Dict[str, Any]: """ Merges `source_dict` into `target_dict`. All values from `source_dict` will either extend or overwrite values in `target_dict`. The merge works recursively. The `target_dict` becomes modified. Args: source_dict (dict): The dict the values should be taken from. target_dict (dict): The dict the values should be applied to. Returns: dict: Returns the modified `target_dict`. """ for key, value in source_dict.items(): if isinstance(value, dict) and key in target_dict: merge_dict(value, target_dict[key]) else: target_dict[key] = value return target_dictMerges
source_dictintotarget_dict.All values from
source_dictwill either extend or overwrite values intarget_dict. The merge works recursively. Thetarget_dictbecomes modified.Args
source_dict:dict- The dict the values should be taken from.
target_dict:dict- The dict the values should be applied to.
Returns
dict- Returns the modified
target_dict.