Given a list x = [1,0,0,1,1]I can use random.shuffle(x) repeatedly to shuffle this list, but if I try to do this a for loop the list doesn't shuffle.
For example:
x = [1,0,0,1,1]
k = []
for i in range(10):
random.shuffle(x)
k.append(x)
return x
Basically, kcontains the same sequence of x unshuffled? Any work around?
random.shuffleis in place. You're fillingkwith references to the same list, so all ten lists in the result will be in the same random order. Maybe try a shallow copy,k.append(x[:])?kactually contains the same sequence ofxshuffled, but there are only so many unique orders so sometimes it will be the same as your starting position.