optimization question

Andrew Koenig ark at research.att.com
Mon Aug 12 00:13:06 CEST 2002


>> def eqsub(s, i, j, t):
>> return (len(t) == j-i) and s[i:j] == t
>> 
>> which avoids building the substrings unless necessary.
>> 

Bernard> Wouldn't the following avoid it altogether?

Bernard>     return (len(t) == j-i) and (s.find(t,i) != -1)

Yes, it looks like it would.  On the other hand, I might want
to generalize the technique to sequences other than strings...

-- 
Andrew Koenig, ark at research.att.com, http://www.research.att.com/info/ark



More information about the Python-list mailing list