Permutations with generators

Pablo Torres tn.pablo at gmail.com
Sat Jul 21 08:18:45 CEST 2007


>
> list.insert returns None.  Thus, except in the one-element case, your
> generator is yielding None all the time.
>

Oh god...silly me.
Thank you guys for the help :)

P.S I'm dead stubborn, so here's what I did to fix my code:

def perm(seq):
	"Reshuffles the elements of seq in every possible way"
	if len(seq) == 1:
		yield seq
	else:
		for i in range(len(seq)):
			for p in perm(seq[1:]):
                                # Here:
				p.insert(i, seq[0])
				yield p





More information about the Python-list mailing list