String comparison

Brian Jones bejones at hursley.ibm.com
Thu Aug 22 04:57:20 EDT 2002


> if s1.lower() == s2.lower():
>    blah()
> 
> I suppose this would do the trick, too:
> 
> if re.match( '^' + s1 + '$', s2, re.I ):
>    blah()
> 
> I'm not sure which of these is better (or maybe it is neither!), though, so,
> of course, I'd like to know what the One True Path is...

As a real Python newbie making his first post here may I vote for the 
former.

For me one of Python's great strengths is that it does not carry the 
baggage of C++ or Java, and avoids the obfuscation of Perl (and readily 
available in C). It is clean and intrinsically simple.

The first of your choices bears the simplicity of Python whilst the 
second reminds me of Perl.

Regexs are powerful when they are needed but why add complexity and 
decrease readability where they are not needed.

Brian



More information about the Python-list mailing list