def random_flip_mutate(population, mutation_chance):
    """Mutate every chromosome in a population, list is modified in place.

    Mutation occurs by randomly flipping bits (genes).
    """
    for chromosome in population:  # For every chromosome in the population
        for i in range(len(chromosome)):  # For every bit in the chromosome
            # If mutation takes place
            if random.uniform(0.0, 1.0) <= mutation_chance:
                chromosome[i] = 1 - chromosome[i]
def random_flip_mutate ( population , mutation_chance ) : for chromosome in population : for i in range ( len ( chromosome ) ) : if random . uniform ( 0.0 , 1.0 ) <= mutation_chance : chromosome [ i ] = 1 - chromosome [ i ]
Mutate every chromosome in a population, list is modified in place.

    Mutation occurs by randomly flipping bits (genes).