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