Re: problem with permutations

2008-09-07 Thread Paul Rubin
cnb <[EMAIL PROTECTED]> writes: > perms([]) -> [[]]; > perms(L) -> [[H|T] || H <- L, T <- perms(L--[H])]. I think the most direct transcription might be: def perms(xs): if len(xs)==0: return [[]] return [([h]+t) for h in xs for t in perms([y for y in xs if y

Re: problem with permutations

2008-09-07 Thread James Mills
Hi, Here's a (better?) function: def permutate(seq): if not seq: return [seq] else: temp = [] for k in range(len(seq)): part = seq[:k] + seq[k+1:] for m in permutate(part): temp.append(seq[k:k+1] + m) return temp che

problem with permutations

2008-09-07 Thread cnb
I am trying to translate this elegant Erlang-code for finding all the permutations of a list. I think it is the same function as is but it doesn't work in Python. -- is upd in Python. It works as it should. perms([]) -> [[]]; perms(L) -> [[H|T] || H <- L, T <- perms(L--[H])]. def perms(lista):