optimization question

Emile van Sebille emile at fenx.com
Sun Aug 11 13:04:34 EDT 2002


"Andrew Koenig" <ark at research.att.com> wrote in message
news:yu994re14cla.fsf at europa.research.att.com...
> If s and t are strings, and I evaluate an expression of the form
>
>     s[i:j] == t
>
> can I count on the implementation not to form s[i:j] as a new
> substring?  Suppose, for instance, that s is many megabytes
> long, i and j are far apart, and t is very short.  Can I assume
> that the execution time for this comparison will be no worse
> than O(len(t)), or must I assume O(j-1)?

ISTM that the right and left sides are built before being passed to
strcmp, and if I'm seeing that right, this might help:


>>> def test(s,i,j,t):
...     return len(t) == (j-i) and s[i:j] == t

--

Emile van Sebille
emile at fenx.com

---------




More information about the Python-list mailing list