optimization question
Matt Gerrans
mgerrans at mindspring.com
Sun Aug 11 15:56:57 EDT 2002
> and call this function everywhere instead of doing direct comparisons.
> Then the optimization becomes trivial:
>
> def eqsub(s, i, j, t):
> return (len(t) == j-i) and s[i:j] == t
I think this might add some additional speed (depending on the likelyhood of
matches), since indexing a single character doesn't do a slice (based on
what dis shows):
def eqsub(s, i, j, t):
return (len(t) == j-i) and (s[i]==t[0]) and (s[i:j] == t)
- Matt
More information about the Python-list
mailing list