Case-insensitive string compare?

Robert Dailey rcdailey at gmail.com
Thu Sep 4 19:48:55 EDT 2008


On Thu, Sep 4, 2008 at 5:59 PM, Maric Michaud <maric at aristote.info> wrote:

> Le Friday 05 September 2008 00:47:00 Chris Rebert, vous avez écrit :
> >
> > Then store the string in its original case in the value part of the
> > key-value pair:
> >
> > stage_map[key.lower()] = (key,whatever)
> >
>
> "premature optimization is the root of all evil"
>
> I don't recall the OP wanted a (a bit) faster solution to his problem in
> counterpart of memory loss and syntax complication.
>
> 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() ) :
>    ...



Thanks everyone for your help. I'm not opposed to using [key.lower() for key
in stage_map] at all, I was just curious to see if there were any cleaner
alternatives. It looks like that is what I'll be using. I'm not familiar
with how python works internally, but coming from C++ it seems like
"remaking" the map would be slow. However, speed is not my main concern in
my particular situation, I'm just curious to learn more about python.

Thanks again everyone.
-------------- next part --------------
An HTML attachment was scrubbed...
URL: <http://mail.python.org/pipermail/python-list/attachments/20080904/709a8337/attachment.html>


More information about the Python-list mailing list