Possible Duplicate:
Shuffle an array with python
let's say I have a list myList=[1,2,3,4,5]
,and I want to disorder it randomly:
disorder(myList) # myList is something like [5,3,2,1,4] or [3,5,1,2,4] now
the way I am using is
from random import randint
upperBound = len(myList)-1
for i in range(10):
myList.insert(randint(0, upperBound), myList.pop(randint(0, upperBound)))
this works, but I think it's obviously inelegant. I am wondering whether there is an elegant and efficient way to achieve my goal.