Sorted list - how to change it

Lad python at hope.cz
Thu Nov 9 04:58:13 EST 2006


Wolfram Kraus wrote:
> On 09.11.2006 10:52, Lad wrote:
> > I have a sorted list for example [1,2,3,4,5] and I would like to change
> > it in a random way
> > e.g [2,5,3,1,4] or [3,4,1,5,2]  or in any other way except being
> > ordered.
> > What is the best/easiest
> >  way how to do it?
> >
> > Thank you for help
> > L.
> >
> use random.shuffel:
>
> >>> import random
> >>> x = [1,2,3,4,5]
> >>> random.shuffle(x)
> >>> x
> [1, 4, 2, 3, 5]
> >>> random.shuffle(x)
> >>> x
> [4, 2, 1, 3, 5]
>
> see: http://docs.python.org/lib/module-random.html
 Wolfram,
Thanks a lot for help
L.




More information about the Python-list mailing list