Enumerating k-segmentations of a sequence
dickinsm at gmail.com
Tue Nov 25 18:41:34 CET 2008
On Nov 25, 5:34 pm, Mark Dickinson <dicki... at gmail.com> wrote:
> If you have Python 2.6 available, itertools.combination might be
That should be itertools.combinations, of course.
The idea is that to give a partition of e.g., a 5-element list
into 3 nonempty pieces, all you have to do is say where to break
the list. There are 4 possible places to break (between the
1st and 2nd elements, 2nd and 3rd, etc.), and you've got to
make two breaks. Then combinations(range(1, 5), 2) generates
all possible pairs of breaking points.
More information about the Python-list