[Python-ideas] proposed sequence method: index_subseq()

Terry Reedy tjreedy at udel.edu
Tue Aug 27 22:21:25 CEST 2013


On 8/27/2013 1:34 PM, Steven D'Aprano wrote:
> On 28/08/13 00:57, Jess Austin wrote:
>> Recently I've repeatedly needed to check whether a particular sequence
>> occurred as a "subsequence" of another. I think this could be a general
>> requirement, so I'd like to ask if anyone else agrees.

I think the need is too specialized for the stdlib. On the otherhand, a 
generalized subsequence module on PyPI would be fine if there is none 
there already. If you call the initial releases 'alpha', you would be 
free to experiments with the apis.

> I dislike that. The end and step parts of the slice are redundant: end
> is easily calculated as just start + len(subseq), and step will always
> be None. A more familiar, and obvious, functionality is to return the
> starting index, and then either raise an exception if not found, or
> return some sentinel value (not -1 since it can be used as an index in
> error).

There are subsequence algorithms that see, for instance, 1,4,7 as a 
subsequence of 0,1,2,3,4,5,6,7,8.


-- 
Terry Jan Reedy



More information about the Python-ideas mailing list