Unsorting(randomizing) a sequence

Dan Schmidt dfan at harmonixmusic.com
Tue Aug 17 16:44:28 EDT 1999


Ole-Kristian Villaboe <olevi at my-deja.com> writes:

| Is there a command to do this? (Can't find one but...)
| I've been writing an algorithm myself, but it's incredibly slow and I
| would like something quicker (of course :) )

This is slower and takes more space than the correct solution already
posted, but it's kind of fun:

def randomize (l):
    l2 = map (lambda x: (whrandom.random(), x), l)
    l2.sort()
    return map (lambda x: x[1], l2)

-- 
                 Dan Schmidt -> dfan at harmonixmusic.com, dfan at alum.mit.edu
Honest Bob & the                http://www2.thecia.net/users/dfan/
Factory-to-Dealer Incentives -> http://www2.thecia.net/users/dfan/hbob/
          Gamelan Galak Tika -> http://web.mit.edu/galak-tika/www/




More information about the Python-list mailing list