Tim Chase <[EMAIL PROTECTED]> wrote:
> Just a caveat from past experience...while the OP was talking
> about lists, for future reference random.shuffle() chokes on
> strings (and possibly tuples). It requires the ability to edit
> the target/parameter in place...a functionality that strings
Lad a écrit :
> 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.
Not accepting that the shuffle outp
In <[EMAIL PROTECTED]>, Marc 'BlackJack' Rintsch
wrote:
> lst = [1, 2, 3, 4, 5]
> tmp = list(lst)
> while lst == tmp:
> random.shuffle(lst)
Argh, that fails if the list is empty or contains just one item.
lst = [1, 2, 3, 4, 5]
if len(lst) > 1:
tmp = list(lst)
while lst == tmp:
>> 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?
>
> use random.shuffel:
>
import random
x = [1,2,3,4,5]
In <[EMAIL PROTECTED]>, 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.
lst = [1, 2, 3, 4, 5]
tmp = list(lst)
while lst == tmp:
random.shuffle(lst)
If you *
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?
> >
> > Th
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.shu