Re: Sorted list - how to change it

2006-11-09 Thread Nick Craig-Wood
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

Re: Sorted list - how to change it

2006-11-09 Thread Christophe
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

Re: Sorted list - how to change it

2006-11-09 Thread Marc 'BlackJack' Rintsch
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:

Re: Sorted list - how to change it

2006-11-09 Thread Tim Chase
>> 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]

Re: Sorted list - how to change it

2006-11-09 Thread Marc 'BlackJack' Rintsch
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 *

Re: Sorted list - how to change it

2006-11-09 Thread Lad
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

Re: Sorted list - how to change it

2006-11-09 Thread Wolfram Kraus
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