String functions: what's the difference?

gry at ll.mit.edu gry at ll.mit.edu
Thu Mar 9 09:57:08 EST 2006


First, don't appologize for asking questions.  You read, you thought,
and you tested.  That's more than many people on this list do.  Bravo!

One suggestion: when asking questions here it's a good idea to always
briefly mention which version of python and what platform (linux,
windows, etc) you're using.  It helps us answer your questions more
effectively.

For testing performance the "timeit" module is great.  Try something
like:
  python -mtimeit -s 'import string;from myfile import isLower'
"isLower('x')"

You didn't mention the test data, i.e. the character you're feeding to
isLower.
It might make a difference if the character is near the beginning or
end of the range.

As to reasons to prefer one or another implementation, one *very*
important question is "which one is clearer?".  It may sound like a
minor thing, but when I'm accosted first thing in the
morning(pre-coffee) about a nasty urgent bug and sit down to pore over
code and face "string.find(string.lowercase, ch) != -1", I'm not happy.

Have fun with python!
-- George Young




More information about the Python-list mailing list