Case-insensitive string compare?
Fredrik Lundh
fredrik at pythonware.com
Thu Sep 4 18:21:59 EDT 2008
Robert Dailey wrote:
> 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?
dictionary lookups use the exact value. to make a case-insensitive
lookup, use key.lower() instead of key when creating the dictionary, and
then do
if lib.lower() not in state_map:
...
</F>
More information about the Python-list
mailing list