dimanche 25 novembre 2018

Python: Randomly mix two lists

I'm having some trouble mixing two lists together to make a new list of the same length.

So far I ave randomly selected two lists from a bunch of lists called parent 1 and parent 2. This is what I have so far but the output_list line doesn't work.

parent1 = listname[random.randint(1,popsize)]
parent2 = listname[random.randint(1,popsize)]
output_list = random.choice(concatenate([parent1,parent2]), length, replace=False)
print(output_list)

The outcome I want it if parent 1 = [1,2,3,4,5] and parent 2 = [6,7,8,9,10] then a possible outcome could be [1,2,3,9,10] or [1,7,2,5,6] or [1,2,7,4,5].

Anybody have any ideas?

(the context is two sets of genes which breed to form a child with a mix of the parents genes)




Aucun commentaire:

Enregistrer un commentaire