code: def merge_dict(dict1, dict2):
      # type: (dict, dict) -> dict
      
      if not isinstance(dict1, dict) or not isinstance(dict2, dict):
          raise ValueError('dict1 or dict2 is not a dictionary')
      result = copy.deepcopy(dict1)
      for k, v in dict2.items():
          if k in result and isinstance(result[k], dict):
              result[k] = merge_dict(result[k], v)
          else:
              result[k] = copy.deepcopy(v)
      return result
docs: Recursively merge dictionaries: dict2 on to dict1. This differs
      from dict.update() in that values that are dicts are recursively merged.
      Note that only dict value types are merged, not lists, etc.
  
      :param dict dict1: dictionary to merge to
      :param dict dict2: dictionary to merge with
      :rtype: dict
      :return: merged dictionary