Unsorting(randomizing) a sequence

Magnus L. Hetland mlh at idt.ntnu.no
Wed Aug 18 00:40:14 CEST 1999


Skip Montanaro <skip at mojam.com> writes:

>     Ole> I've been writing an algorithm myself, but it's incredibly slow and
>     Ole> I would like something quicker (of course :) )

result = []
for i in range(len(l)):
    element = random.choice(list)
    l.remove(element)
    result.append(element)

Probably not that quick, but...

--

  Magnus              Making no sound / Yet smouldering with passion
  Lie          The firefly is still sadder / Than the moaning insect
  Hetland                                       : Minamoto Shigeyuki




More information about the Python-list mailing list