I want to shuffle an array, but all I find was method like random.shuffle(x)
, from Best way to randomize a list of strings in Python
Can I do something like
import random
rectangle = [(0,0),(0,1),(1,1),(1,0)]
# I want something like
# disorderd_rectangle = rectangle.shuffle
Now I can only get away with
disorderd_rectangle = rectangle
random.shuffle(disorderd_rectangle)
print(disorderd_rectangle)
print(rectangle)
But it returns
[(1, 1), (1, 0), (0, 1), (0, 0)]
[(1, 1), (1, 0), (0, 1), (0, 0)]
So the original array
is also changed. How can I just create another shuffled array
without changing the original one?