Re: [Tutor] permutations using list comprehensions

2005-05-01 Thread Danny Yoo
> The best I've been able to do is pretty obvious:- > def perms (t): > if len (t) == 0: > return [] > else: > return [[x] + perms ([y for y in t if y <> x]) for x in t] > >Needless to say, it doesn't work. It does produce a list of > lists but they are so horribly n

Re: [Tutor] permutations using list comprehensions

2005-05-01 Thread Karl Pflästerer
On 1 Mai 2005, [EMAIL PROTECTED] wrote: > I'm trying to produce something of a similar structure to generate the > permutations of a sequence by translating the ffg bit of Haskell:- > perms [] = [[]] > perms xs = [ x : ps | x <- xs , ps <- perms ( xs\\[x]) ] > > '\\' applies to lists & means ele

[Tutor] permutations using list comprehensions

2005-05-01 Thread Logesh Pillay
Dear list I was really impressed by this version of quicksort:- def qsort (t): if len (t) == 0: return [] else: return qsort([x for x in t[1:] if x <= t[0]]) + [t[0]] + qsort([x for x in t[1:] if x > t[0]]) I'm trying to produce something of a similar structure to generate the