shuffling elements of a list
Scott David Daniels
scott.daniels at acm.org
Wed May 31 00:47:50 EDT 2006
greenflame wrote:
> Zhang Fan wrote:
>> ... 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.
Using Python 2.3.4 on Windows 2000, I get:
import random
lst = range(52)
random.shuffle(lst)
print lst
[8, 26, 9, 10, 22, 39, 36, 48, 29, 5, 50, 16, 15, 2, 40, 33, 3, 7, 37,
43, 11, 0, 30, 49, 32, 44, 24, 47, 42, 27, 23, 28, 12, 18, 13, 35, 1,
34, 25, 45, 21, 20, 46, 38, 17, 31, 6, 4, 14, 41, 51, 19]
Don't be so sure the advice you get is wrong.
--Scott David Daniels
scott.daniels at acm.org
More information about the Python-list
mailing list