def deepupdate(target, src, overwrite=True):
    """Deep update target list, dict or set or other iterable with src
    For each k,v in src: if k doesn't exist in target, it is deep copied from
    src to target. Otherwise, if v is a list, target[k] is extended with
    src[k]. If v is a set, target[k] is updated with v, If v is a dict,
    recursively deep-update it. If `overwrite` is False, existing values in
    target will not be overwritten.

    Examples:
    >>> t = {'name': 'Ferry', 'hobbies': ['programming', 'sci-fi']}
    >>> deepupdate(t, {'hobbies': ['gaming']})
    >>> print t
    {'name': 'Ferry', 'hobbies': ['programming', 'sci-fi', 'gaming']}
    """
    for k, v in src.items():
        if type(v) == list:
            if not k in target:
                target[k] = copy.deepcopy(v)
            elif overwrite is True:
                target[k].extend(v)
        elif type(v) == dict:
            if not k in target:
                target[k] = copy.deepcopy(v)
            else:
                deepupdate(target[k], v, overwrite=overwrite)
        elif type(v) == set:
            if not k in target:
                target[k] = v.copy()
            elif overwrite is True:
                if type(target[k]) == list:
                    target[k].extend(v)
                elif type(target[k]) == set:
                    target[k].update(v)
                else:
                    raise TypeError("Cannot update {} with {}".format(type(target[k]), type(v)))
        else:
            if k not in target or overwrite is True:
                target[k] = copy.copy(v)
def deepupdate ( target , src , overwrite = True ) : for k , v in src . items ( ) : if type ( v ) == list : if not k in target : target [ k ] = copy . deepcopy ( v ) elif overwrite is True : target [ k ] . extend ( v ) elif type ( v ) == dict : if not k in target : target [ k ] = copy . deepcopy ( v ) else : deepupdate ( target [ k ] , v , overwrite = overwrite ) elif type ( v ) == set : if not k in target : target [ k ] = v . copy ( ) elif overwrite is True : if type ( target [ k ] ) == list : target [ k ] . extend ( v ) elif type ( target [ k ] ) == set : target [ k ] . update ( v ) else : raise TypeError ( "Cannot update {} with {}" . format ( type ( target [ k ] ) , type ( v ) ) ) else : if k not in target or overwrite is True : target [ k ] = copy . copy ( v )
Deep update target list, dict or set or other iterable with src
    For each k,v in src: if k doesn't exist in target, it is deep copied from
    src to target. Otherwise, if v is a list, target[k] is extended with
    src[k]. If v is a set, target[k] is updated with v, If v is a dict,
    recursively deep-update it. If `overwrite` is False, existing values in
    target will not be overwritten.

    Examples:
    >>> t = {'name': 'Ferry', 'hobbies': ['programming', 'sci-fi']}
    >>> deepupdate(t, {'hobbies': ['gaming']})
    >>> print t
    {'name': 'Ferry', 'hobbies': ['programming', 'sci-fi', 'gaming']}