import statistics


def summary(population_trace):
    """Compute min, max and mean value for each iteration.

    Arguments:
        population_trace: list of populations' coordinates in each iteration

    Return:
        dictionary with keys:
            - max_fitness - list of max fitnesses in each iteration
            - min_fitness - list of min fitnesses in each iteration
            - mean_fitness - list of mean fitnesses in each iteration

    """
    max_fitness = []
    min_fitness = []
    mean_fitness = []

    for iteration in population_trace:
        max_fitness.append(max(iteration, key=lambda x: x[-1])[-1])
        min_fitness.append(min(iteration, key=lambda x: x[-1])[-1])
        mean_fitness.append(statistics.mean(individual[-1] for individual in iteration))

    return {
        "max_fitness": max_fitness,
        "min_fitness": min_fitness,
        "mean_fitness": mean_fitness,
    }