def invert_mapping(mapping):
    """ Invert a mapping dictionary

    Parameters
    ----------
    mapping: dict

    Returns
    -------

    """
    inverted_mapping = defaultdict(list)
    for key, value in mapping.items():
        if isinstance(value, (list, set)):
            for element in value:
                inverted_mapping[element].append(key)
        else:
            inverted_mapping[value].append(key)

    return inverted_mapping