tags:

views:

63

answers:

3

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 in order to obtain a list:

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

without consuming a lot of the system's resources?

+4  A: 
import random
b = list(a)
random.shuffle(b)
Matthew Flaschen
Python: just try the verb you are thinking™.
Agos
+3  A: 

random.shuffle() shuffles a sequence in-place.

Ignacio Vazquez-Abrams
+1  A: 

Not sure how much resources it consumes, but shuffle in the random module does exactly like this.

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