Partition Problem
David Eppstein
eppstein at ics.uci.edu
Mon Jul 23 13:01:00 EDT 2001
In article <Xns90E765BFABFB7duncanrcpcouk at 127.0.0.1>,
Duncan Booth <duncan at NOSPAMrcp.co.uk> wrote:
> def permute(seq):
> if len(seq)==1:
> yield seq
> return
>
> for i in range(len(seq)):
> for perm in permute(seq[:i] + seq[i+1:]):
> yield seq[i:i+1] + perm
Nice, but shouldn't the len(seq)==1 test actually be <=1?
The empty sequence has one permutation, not zero.
--
David Eppstein UC Irvine Dept. of Information & Computer Science
eppstein at ics.uci.edu http://www.ics.uci.edu/~eppstein/
More information about the Python-list
mailing list