def filter_dict(data, include, exclude, joinchar='.'):
    """
    Filter a dictionary using the provided include and exclude patterns.

    :param dict data: The data to filter
     (dict or OrderedDict, type is respected).
    :param list include: List of patterns of key paths to include.
    :param list exclude: List of patterns of key paths to exclude.
    :param str joinchar: String used to join the keys to form the path.

    :return: The filtered dictionary.
    :rtype: dict or OrderedDict
    """
    assert isinstance(data, dict)

    def filter_dict_recursive(breadcrumbs, element):
        if not isinstance(element, dict):
            return element

        return element.__class__(
            (key, filter_dict_recursive(breadcrumbs + [key], value))
            for key, value in element.items()
            if is_wanted(joinchar.join(breadcrumbs + [key]), include, exclude)
        )

    return filter_dict_recursive([], data)