Pablo Torres <[EMAIL PROTECTED]> writes: > def perm(seq): > "Reshuffles the elements of seq in every possible way" > if len(seq) == 1: > yield seq > else: > for p in perm(seq[1:]): > for i in range(len(seq)): > yield p.insert(i, seq[0])
It's easiest to avoid these mutating schemes and instead just generate each permutation separately. def perm(seq): if len(seq) == 0: yield [] for (i,s) in enumerate(seq): for p in perm(seq[:i]+seq[i+1:]): yield [s]+p -- http://mail.python.org/mailman/listinfo/python-list