From: Michael Ulm Date: 2005-12-07T00:06:23+09:00 Subject: Re: Shuffling an array, sort_by{rand}'s bias (was Re: need some Ruby Uwe Schmitt wrote: > || arr.sort_by{rand} > > that is not equivalent to my solution. > the python equivalent to yours is > > arr.sort(key = lambda x: random()) > > || > || > In Python it is quite easy by using list comprehensions... > || What does that look like in Python? > > from random import random > > def shuffle(a): > b = [ (random(), i) for i in a] > b.sort() > return [ x[1] for x in b ] > > print shuffle(range(10)) > I would have thought those two functions do the same thing with the exception that shuffle does not sort in place. I'm probably missing something obvious. Could you explain the difference between the two versions? Michael -- Michael Ulm R&D Team ISIS Information Systems Austria tel: +43 2236 27551-219, fax: +43 2236 21081 e-mail: michael.ulm@isis-papyrus.com Visit our Website: www.isis-papyrus.com