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.
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.