def solution(swarm):
    """ Determines the global best particle in the swarm.

    Args:
        swarm: iterable: an iterable that yields all particles in the swarm.

    Returns:
        cipy.algorithms.pso.Particle: The best particle in the swarm when
        comparing the best_fitness values of the particles.
    """
    best = swarm[0]
    cmp = comparator(best.best_fitness)
    for particle in swarm:
        if cmp(particle.best_fitness, best.best_fitness):
            best = particle
    return best
Determines the global best particle in the swarm.

    Args:
        swarm: iterable: an iterable that yields all particles in the swarm.

    Returns:
        cipy.algorithms.pso.Particle: The best particle in the swarm when
        comparing the best_fitness values of the particles.