def invert_dictionary(dict_map):
    """
    Invert a dictionary-mapping such that values point to keys.

    Parameters
    ----------
    dict_map : dict
        dictionary, that shall be inverted

    Returns
    -------
    dict_map_inv : dict
        inverted dictionary
    """
    def add_new_value_to_key(dictionary, key, value):
        if key in dictionary:
            if not isinstance(dictionary[key], list):
                dictionary[key] = [dictionary[key]]
            dictionary[key].append(value)
        else:
            dictionary[key] = value
        return dictionary

    dict_map_inv = dict()
    for k, v in dict_map.items():
        dict_map_inv = add_new_value_to_key(dict_map_inv, v, k)

    return dict_map_inv