How do I do a case insensitive string comparison in Python?

What's the best way to 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. Much obliged for advice.

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

Add a checkbox to each row of a ListViewWebpart

sharepoint checkbox wss

I'm working on a WSS 3 site that has a ListViewWebpart displaying various columns.

Console Logs and Alerts not working

javascript jquery console gulp alert

For some reason console.log and alert() functions don't seem to be working across any of my js files.

About UNIX Resources Network

Original, collect and organize Developers related documents, information and materials, contains jQuery, Html, CSS, MySQL, .NET, ASP.NET, SQL, objective-c, iPhone, Ruby on Rails, C, SQL Server, Ruby, Arrays, Regex, ASP.NET MVC, WPF, XML, Ajax, DataBase, and so on.