import random


def mutate(individual, m, k):
    """
    This function apply the mutation operator
    :param k:Number of genes that were chosen to maybe mutate
    :param individual:list
    :param m:Mutation Rate
    :return:Return the individual after the mutation
    """

    lst = random.sample(range(0, len(individual)), k)
    # print(lst)
    for i in lst:
        if random.random() < m:
            if individual[i] == 0:
                individual[i] = 1
    # print(individual)
    return individual