Partition Problem

David Eppstein eppstein at
Mon Jul 23 19:01:00 CEST 2001

In article <Xns90E765BFABFB7duncanrcpcouk at>,
 Duncan Booth <duncan at> 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

More information about the Python-list mailing list