code: def _crossover(population, crossover_chance, crossover_operator):
      
      new_population = []
      for i in range(0, len(population), 2):  # For every other index
          # Take parents from every set of 2 in the population
          # Wrap index if out of range
          try:
              parents = (population[i], population[i + 1])
          except IndexError:
              parents = (population[i], population[0])
  
          # If crossover takes place
          if random.uniform(0.0, 1.0) <= crossover_chance:
              # Add children to the new population
              new_population.extend(crossover_operator(parents))
          else:
              new_population.extend(parents)
  
      return new_population
docs: Perform crossover on a population, return the new crossed-over population.