import random


def mutSet(individual, possible_values: list):
    """
    Mutation that pops or add an element.

    Parameters
    ----------
    individual: Set
        Individual to be mutated.

    possible_values: list
        List of possible values to insert into the individual.

    Returns
    -------
    :tuple
        :[0]: Set
            Mutated individual.
    """
    if random.random() < 0.5:
        if len(individual) > 0:     # We cannot pop from an empty set
            individual.remove(random.choice(sorted(tuple(individual))))
    else:
        individual.add(random.choice(list(possible_values)))
    return individual,