Shuffle a list and return a copy

Use copy.deepcopy to create a copy of the array, shuffle the copy.

c = copy.deepcopy(rectangle)
random.shuffle(c)

People here are advising deepcopy, which is surely an overkill. You probably don't mind the objects in your list being same, you just want to shuffle their order. For that, list provides shallow copying directly.

rectangle2 = rectangle.copy()
random.shuffle(rectangle2)

About your misconception: please read http://nedbatchelder.com/text/names.html#no_copies


You need to make a copy of the list, by default python only creates pointers to the same object when you write:

disorderd_rectangle = rectangle

But instead use this or the copy method mentioned by Veky.

disorderd_rectangle = rectangle[:]

It will make a copy of the list.