Python – shuffle only some elements of a list

What you do is this:

copy = list[2:]
random.shuffle(copy)    

which does not do much to the original list. Try this:

copy = list[2:]
random.shuffle(copy)
list[2:] = copy # overwrite the original

Leave a Comment