How can I eliminate the double values that appear in some lists?
def selection_and_reproduction(poblacionNueva):
puntuados = [ [calcularFitness(i), i] for i in poblacionNueva] #Calcula el fitness de cada individuo, y lo guarda en pares ordenados de la forma (5 , [1,2,1,1,4,1,8,9,4,1])
def takeSecond(puntuados):
return puntuados[0]
puntuados = sorted(puntuados, key=takeSecond)
print("Puntuados:\n%s"%(puntuados))
poblacionNueva = puntuados
selected = puntuados[(len(puntuados)-indAReproducir):]
lista = list(range(1, largo))
print("LISTA:\n%s"%(lista))
random.shuffle(lista)
print("LISTA ALEATORIA:\n%s"%(lista))
for i in lista:
i = i-1
punto =lista[i]
padre = random.sample(selected, 2)
print("Punto:%s"%(punto))
print("Padre:%s"%(padre))
poblacionNueva[i][:punto] = (padre[0])[1][:punto]
print("Primera parte:%s"%(poblacionNueva[i][:punto]))
poblacionNueva[i][punto:] = (padre[1])[1][punto:]
print("Segunda parte:%s"%(poblacionNueva[i][punto:]))
i = poblacionNueva[i][:punto] + poblacionNueva[i][punto:]
print("Individuo Generado:%s"%(i))
print("Fitness de I:%s"%(calcularFitness(i)))
print("Individuo Generado CON FITNESS:%s"%(i))
poblacionNueva = [i for i in poblacionNueva]
print("Poblacion Nueva FINAL:\n%s"%(poblacionNueva))
return poblacionNueva
It would be necessary to remove the value of the last lists from NewPopulation :
EDIT 1: I have used both Del and pop. It eliminates the value but it leaves me the empty space of the first list in the last two that I need to eliminate it too.