

def deep_update_dict(dict1, dict2, update_dict1=True):
    "\n\n    >>> expected_dict = {'list': [1, 2, 3, 4], 'answer': 42, 'key': 'value0', 'dict': {'key1': 'value1', 'key2': 'value2'}, 'set': {1, 3, 4}}\n    >>> dict1 = {'answer': 42, 'key': 'value', 'dict': {'key1': 'value1'}, 'list': [1, 2, 3], 'set': {1, 3}}\n    >>> dict2 = {'key': 'value0', 'dict': {'key2': 'value2'}, 'list': [3, 4], 'set': {1, 4}}\n    >>> dict3 = deep_update_dict(dict1, dict2, update_dict1=False)\n    >>> dict1 is dict3\n    False\n    >>> dict3 == expected_dict\n    True\n    >>> import copy\n    >>> dict4 = copy.deepcopy(dict1)\n    >>> dict5 = copy.deepcopy(dict2)\n    >>> dict6 = deep_update_dict(dict4, dict5)\n    >>> dict4 is dict6\n    True\n    >>> dict6 == expected_dict\n    True\n\n\n    :type dict1: dict\n    :type dict2: dict\n    :rtype: dict\n    "
    if (not update_dict1):
        dict1 = copy.deepcopy(dict1)
    for (key, dict2_value) in dict2.items():
        if (key not in dict1):
            dict1[key] = dict2_value
        else:
            dict1_value = dict1[key]
            if (isinstance(dict1_value, list) and isinstance(dict2_value, list)):
                seen_items = set()
                dict1[key] = [item for item in (dict1_value + dict2_value) if (not ((item in seen_items) or seen_items.add(item)))]
            elif (isinstance(dict1_value, dict) and isinstance(dict2_value, dict)):
                dict1[key] = deep_update_dict(dict1_value, dict2_value, update_dict1=update_dict1)
            elif (isinstance(dict1_value, set) and isinstance(dict2_value, set)):
                dict1[key] = (dict1_value | dict2_value)
            else:
                dict1[key] = dict2_value
    return dict1

dataset/ETHPy150Open sodastsai/taskr/taskr/contrib/collections.py deep_update_dict/original