Faster 'if char in string' test

Kamilche klachemin at home.com
Thu Jun 24 16:49:53 EDT 2004


elbertlev at hotmail.com (Elbert Lev) wrote in message news:<9418be08.0406240642.6b7797f at posting.google.com>...

> 
> translate method is much slower then "c in string" method in the case
> when the test string is very long (say 5mb) and the invalid character
> is located close to the beginning of the string. (10000 times slower!)

Good point! I was surprised that allocating a fresh string and
comparing lengths was speedier, but upon reflection, I could see how
that could be so. And I also see how if it was a HUMONGOUS string, a
book more like, this would no longer be the case.

Thanks for pointing that out!



More information about the Python-list mailing list