How do I do a case-insensitive string comparison?

How can I do case insensitive string comparison in Python?

I would like to encapsulate comparison of a regular strings to a repository string using in a very simple and Pythonic way. I also would like to have ability to look up values in a dict hashed by strings using regular python strings.

Answers


Assuming ASCII strings:

string1 = 'Hello'
string2 = 'hello'

if string1.lower() == string2.lower():
    print("The strings are the same (case insensitive)")
else:
    print("The strings are NOT the same (case insensitive)")

Need Your Help

GWT/Apache POI Download Servlet: Incorrect filename on download

java excel tomcat gwt servlets

I have a servlet that creates a dynamic Excel spreadsheet using Apache POI. I can create the spreadsheet just fine. However, when I use Google Chrome and a Tomcat server, the downloaded file does...