vendredi 8 octobre 2021

python using random.shuffle() on only part of a list

I am trying to implement a genetic algorithm in python. I have a list of 100 objects, sorted, and I need to access the top 30 plus 20 random others. My method is:

random.shuffle(list[30:])  #keep top 30, shuffle the rest
for x in range (50):
    list[x].do_stuff

This doesn't work, the list is unchanged. Is my syntax wrong or is my entire method impossible? thanks




Aucun commentaire:

Enregistrer un commentaire