Permuting data

Gerhard Häring gerhard.haering at opus-gmbh.net
Wed Nov 20 15:45:56 EST 2002


In article <3DDBE5D6.20501 at domain.invalid>, user at domain.invalid wrote:
> Hi,
> I have encountered a following problem: I need to permute randomly 200 
> lines of data  100 times... Meaning that each iteration, data lines are 
> in the random order. What would be the proper way to do it?

One way is to use the 'shuffle' function in from the 'random' module:

>>> from random import shuffle
>>> l = [3,4,5,6]
>>> shuffle(l)
>>> l
[5, 4, 3, 6]
>>> shuffle(l)
>>> l
[6, 3, 4, 5]

HTH,
-- 
Gerhard Häring
OPUS GmbH München
Tel.: +49 89 - 889 49 7 - 32
http://www.opus-gmbh.net/



More information about the Python-list mailing list