Re: Enumerating k-segmentations of a sequence

2008-11-26 Thread bullockbefriending bard
On Nov 26, 12:15 am, [EMAIL PROTECTED] wrote: bullockbefriending bard napisa³(a): I'm not sure if my terminology is precise enough, but what I want to do is: Given an ordered sequence of n items, enumerate all its possible k- segmentations. This is *not* the same as enumerating the

Enumerating k-segmentations of a sequence

2008-11-25 Thread bullockbefriending bard
I'm not sure if my terminology is precise enough, but what I want to do is: Given an ordered sequence of n items, enumerate all its possible k- segmentations. This is *not* the same as enumerating the k set partitions of the n items because I am only interested in those set partitions which

Re: Enumerating k-segmentations of a sequence

2008-11-25 Thread marek . rocki
bullockbefriending bard napisał(a): I'm not sure if my terminology is precise enough, but what I want to do is: Given an ordered sequence of n items, enumerate all its possible k- segmentations. This is *not* the same as enumerating the k set partitions of the n items because I am only

Re: Enumerating k-segmentations of a sequence

2008-11-25 Thread Mark Dickinson
On Nov 25, 4:56 pm, bullockbefriending bard [EMAIL PROTECTED] wrote: I'm not sure if my terminology is precise enough, but what I want to do is: [snip problem description] Structural Recursion not being my strong point, any ideas on how to go about this would be much appreciated! If you have

Re: Enumerating k-segmentations of a sequence

2008-11-25 Thread Mark Dickinson
On Nov 25, 5:34 pm, Mark Dickinson [EMAIL PROTECTED] 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

Re: Enumerating k-segmentations of a sequence

2008-11-25 Thread bearophileHUGS
My version: from itertools import combinations as xcombinations from itertools import izip, islice def xpairwise(iterable): # docs and doctests removed return izip(iterable, islice(iterable, 1, None)) def segmentations(seq, k): for comb in xcombinations(range(1, len(seq)), k-1):

Re: Enumerating k-segmentations of a sequence

2008-11-25 Thread Arnaud Delobelle
bullockbefriending bard [EMAIL PROTECTED] writes: I'm not sure if my terminology is precise enough, but what I want to do is: Given an ordered sequence of n items, enumerate all its possible k- segmentations. This is *not* the same as enumerating the k set partitions of the n items

Re: Enumerating k-segmentations of a sequence

2008-11-25 Thread Gerard flanagan
bullockbefriending bard wrote: I'm not sure if my terminology is precise enough, but what I want to do is: Given an ordered sequence of n items, enumerate all its possible k- segmentations. This is *not* the same as enumerating the k set partitions of the n items because I am only interested