Shuffle items in list

Possible duplicate:
Shuffling a list of objects in python

IF I have a list:

a = ["a", "b", "c", ..., "zzz"]

how can I randomly shuffle its elements to get a list:

b = ["c", "zh", ...]

without consuming a lot of system resources?

+4
source share
3 answers
import random b = list(a) random.shuffle(b) 
+9
source

random.shuffle() shuffles the sequence in place.

+4
source

Not sure how much resources it consumes, but shuffling in a random module does just that.

 import random a = [1,2,3,4,5] random.shuffle(a) 
+2
source

All Articles