Case-insensitive string compare?

Robert Dailey rcdailey at gmail.com
Thu Sep 4 18:15:16 EDT 2008


On Thu, Sep 4, 2008 at 5:14 PM, Robert Dailey <rcdailey at gmail.com> wrote:

> Hi,
>
> I currently have a dictionary object that I'm doing the following with:
>
> if lib not in stage_map:
>     # ... do stuff ...
>
> However, this will perform a case-sensitive comparison between lib and each
> key in stage_map. Is there a way to make this do a case-insensitive
> comparison instead? Yes, I realize I could do this:
>
> if lib not in [key.lower() for key in stage_map]
>
> However, I don't want to do this because it'll quickly end up getting
> messy. I want this solution to be an absolute last resort. I'm not a pro
> with python, so I'm hoping there are cleaner alternatives out there. Thanks.
>

I forgot to mention that I'm using Python 3.0 beta 2.
-------------- next part --------------
An HTML attachment was scrubbed...
URL: <http://mail.python.org/pipermail/python-list/attachments/20080904/af61adf5/attachment-0001.html>


More information about the Python-list mailing list