shuffling elements of a list

SuperHik junkytownMAKNI at gmail.com
Wed May 31 12:12:01 CEST 2006


greenflame wrote:
> Zhang Fan wrote:
>> On 30 May 2006 20:18:19 -0700, greenflame <alikakakhel at yahoo.com> wrote:
>>> Second of all, I would like to have
>>> other methods of shuffling, prefererably riffle shuffling and just
>>> plain randomly arranging the elements of the list.
>> The random module has a `shuffle' method.  It  "Shuffle the sequence x
>> in place".
>> It may be help for you
> 
> I am sorry but this does not help much. In my version of python (2.3)
> this method does not seem to exist. Also from the documentation, it
> seems that this method would give a random number.
> 
You should update your Python then ;)
It's a very nice method:

 >>> import random
 >>> random.seed()
 >>>
 >>> list = [1,21,23,4,5]
 >>> random.shuffle(list)
 >>> print list
[5, 4, 23, 1, 21]



More information about the Python-list mailing list