Python: shuffle and create a new array -


i want shuffle array, find method random.shuffle(x), best way randomize list of strings in python

can like

import random rectangle = [(0,0),(0,1),(1,1),(1,0)] # want # disorderd_rectangle = rectangle.shuffle 

now can away with

disorderd_rectangle = rectangle random.shuffle(disorderd_rectangle) print(disorderd_rectangle) print(rectangle) 

but returns

[(1, 1), (1, 0), (0, 1), (0, 0)] [(1, 1), (1, 0), (0, 1), (0, 0)] 

so original array changed. how can create shuffled array without changing original one?

people here advising deepcopy, surely overkill. don't mind objects in list being same, want shuffle order. that, list provides shallow copying directly.

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

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


Comments

Popular posts from this blog

javascript - three.js lot of meshes optimization -

smartface.io - Proper way to change color scheme for whole application -

Email notification in google apps script -