Sorted list - how to change it

Marc 'BlackJack' Rintsch bj_666 at gmx.net
Thu Nov 9 06:28:25 EST 2006


In <pan.2006.11.09.10.05.13.352443 at gmx.net>, 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:
        random.shuffle(lst)

Ciao,
	Marc 'BlackJack' Rintsch




More information about the Python-list mailing list