def merge(source, target):
    """Merge a source dictionary into a target dictionary

    :param source: source dictionary
    :param target: target dictionary
    :return: source merged into target
    """
    for key, value in source.items():
        if isinstance(value, dict):
            # get node or create one
            if key in target and not target[key]:
                target[key] = {}
            node = target.setdefault(key, {})
            merge(value, node)
        else:
            if key in target:
                target_value = target[key]
                if isinstance(target_value, list) and isinstance(value, list):
                    target_value.extend(value)
                    target[key] = target_value
            else:
                target[key] = value

    return target