Case-insensitive string compare?

Fredrik Lundh fredrik at pythonware.com
Fri Sep 5 02:24:29 EDT 2008


Maric Michaud wrote:

> "premature optimization is the root of all evil"

So is use by that statement by people who don't have the slightest idea 
about what it actually means.

The full version is

"We should forget about small efficiencies, say about 97% of the time: 
premature optimization is the root of all evil."

Note the use of "small efficiencies".  That is, in Python, things like 
local binding, inlining, slots, lazy generation of short sequences, etc. 
  That is, things that takes time to write and reduces maintainability.

It's not about having an excuse for writing crappy code with large 
inefficienies.

And it's definitely not about programmers intentionally picking a dumb 
solution so they can optimize it later.

 > If the OP's proposal seems already messy, how about ths one :
 > if lib.lower() not in ( e[0] for e in stage_map.items() ) :
 >     ...

Given that your solution is just a remarkably inefficient way to write 
"lib.lower() not in stage_map", and thus doesn't solve the OP:s problem, 
I suspect you're taking the "evil" part of Hoare's dictum a few bits too 
literally.

</F>




More information about the Python-list mailing list