substring search without using built in utils

Steven D'Aprano steve at REMOVE.THIS.cybersource.com.au
Thu Nov 9 14:33:10 CET 2006


On Thu, 09 Nov 2006 03:31:02 -0800, John Machin wrote:

> 
> Bruno Desthuilliers wrote:
>> Gabriel Genellina wrote:
>> > At Wednesday 8/11/2006 22:29, zeal elite wrote:
>> >
>> >> I am looking for substring search python program without using the
>> >> built in funtions like find, or 'in'.
>> >
>> > The only reasonable usage for such a constraint would be a school
>> > assignment so: don't cheat and do your homework!
>> >
>>
>> OTHO, looking for existing solutions to a same or similar problem and
>> studying them is usually considerer good practice in real-life
>> programming jobs !-)
>>
> 
> Looking at an existing solution for substring search that was coded in
> Python, instead of using the built-in functionality would IMHO be
> considered extremely bad practice in a real-life programming job.

Sure. But what if the data type in question wasn't a string, but a list?


Given a source list, find the offset of a target sub-list within the
source list, in other words, find for lists.

i.e. search(source, target) returns n if source[n:n+len(target)] == target
for any sequence type.

Yes, I know I'm changing the constraints of the problem. Now for a real
challenge, change the search from a one-dimensional data structure to two.

(The solution is left as an exercise for the class.)

-- 
Steve.




More information about the Python-list mailing list