Re: problem with permutations
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
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