Solved: How do I do a case-insensitive string comparison?


How can I compare strings in a case insensitive way in Python?
I would like to encapsulate comparison of a regular strings to a repository string, using simple and Pythonic code. I also would like to have ability to look up values in a dict hashed by strings using regular python strings.

Best Answer:

Assuming ASCII strings:
As of Python 3.3, casefold() is a better alternative:
If you want a more comprehensive solution that handles more complex unicode comparisons, see other answers.

If you have better answer, please add a comment about this, thank you!