def genome_mutation(candidate):
    """Return the mutants created by inversion mutation on the candidates.

    This function performs inversion or insertion. It randomly chooses two
    locations along the candidate and reverses the values within that
    slice. Insertion is done by popping one item and insert it back at random
    position.
    """
    size = len(candidate)
    prob = random.random()
    if .5 > prob:    # Inversion
        p = random.randint(0, size-1)
        q = random.randint(0, size-1)
        if p > q:
            p, q = q, p
        q += 1
        s = candidate[p:q]
        x = candidate[:p] + s[::-1] + candidate[q:]
        return creator.Individual(x),
    else:            # Insertion
        p = random.randint(0, size-1)
        q = random.randint(0, size-1)
        cq = candidate.pop(q)
        candidate.insert(p, cq)
        return candidate,
dataset/ETHPy150Open tanghaibao/jcvi/algorithms/ec.py/genome_mutation/swapped operands of `>`