Skip to content
Fix Code Error

How do I do a case-insensitive string comparison?

March 13, 2021 by Code Error
Posted By: Kozyarchuk

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.

Solution

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)")
Answered By: Harley

Related Articles

  • How do I merge two dictionaries in a single…
  • Swift: How to get substring from start to last index…
  • Append String in Swift
  • How do I include certain conditions in SQL Count
  • Can't install via pip because of egg_info error
  • Raku vs. Perl5, an unexpected result
  • Python - How to assign/map non-sequential JSON…
  • YAML Multi-Line Arrays
  • Java regular expression OR operator
  • What are the undocumented features and limitations…
  • Are dictionaries ordered in Python 3.6+?
  • When dealing with Localizable.stringsdict, why…
  • How to create a laravel hashed password
  • Replace non-ASCII characters with a single space
  • Reference - What does this regex mean?
  • Is ASCII code 7-bit or 8-bit?
  • Force encode from US-ASCII to UTF-8 (iconv)
  • How to "perfectly" override a dict?
  • trouble shoot a creating a mySQL function for…
  • Match two strings in one line with grep
  • Python is not calling fucntions properly
  • What's the difference between eval, exec, and compile?
  • How to create dictionary and add key–value pairs…
  • c++ how to align output with for loop
  • What encoding/code page is cmd.exe using?
  • TypeError: 'type' object is not subscriptable when…
  • Using sed to split a string with a delimiter
  • Update user in CASL
  • More elegant way of declaring multiple variables at…
  • Maven Could not resolve dependencies, artifacts…
  • C# Convert List to Dictionary
  • How to get integer values from a string in Python?
  • How do you create nested dict in Python?
  • template repeat in template repeat
  • Node.js Error: Cannot find module express
  • Usage of __slots__?
  • TypeError: 'str' object is not callable (Python)
  • Git push error: "origin does not appear to be a git…
  • How to track untracked content?
  • Python reading comma seperated list from JSON
  • How to return concatenated string in C
  • (grep) Regex to match non-ASCII characters?
  • Requirejs shim: want to register backbone plugins…
  • Implement Interface with custom method and JpaRepository
  • Why do git fetch origin and git fetch : behave differently?
  • Reference — What does this symbol mean in PHP?
  • List(of String) or Array or ArrayList
  • Different return type for function factory typescript
  • How to concatenate two strings in SQL Server 2005
  • Python3 asyncio: Process tasks from dict and store…
  • Python Unicode Encode Error
  • Get the list of String from a HTTP response in JAVA
  • What is the difference between dict.items() and…
  • Javascript Uncaught TypeError: Cannot read property…
  • How do I get hour and minutes from NSDate?
  • How to create an object property from a variable…
  • npm WARN package.json: No repository field
  • How do you create different variable names while in a loop?
  • How to clone ('fork') your own personal GitHub repo…
  • Error: " 'dict' object has no attribute 'iteritems' "
  • When should iteritems() be used instead of items()?
  • How do I turn a nested dict of lists (with dicts)…
  • What is the best (idiomatic) way to check the type…
  • Changing PowerShell's default output encoding to UTF-8
  • How can I parse a CSV string with JavaScript, which…
  • Push on GIT and Bitbucket
  • Convert CString to const char*
  • Character reading from file in Python
  • Is there a difference between using a dict literal…
  • Install pip in docker
  • Are nested try/except blocks in Python a good…
  • Quicker way to get all unique values of a column in VBA?
  • How can I get list of values from dict?
  • How do you use "git --bare init" repository?
  • Find non-ASCII characters in varchar columns using…
  • How to get string objects instead of Unicode from JSON?
  • What is the preferred syntax for initializing a…
  • multiple login routes using ember-cli-simple-auth
  • git with IntelliJ IDEA: Could not read from remote…
  • Can I access results of "setup_data" from…
  • How do I rename a Git repository?
  • How to use '-prune' option of 'find' in sh?
  • A python class that acts like dict
  • conflicting types error when compiling c program using gcc
  • Check if a given key already exists in a dictionary
  • Remove dataframe row containing a specific in a list…
  • How can I return the entire dictionary?
  • Safe method to get value of nested dictionary
  • The definitive guide to form-based website authentication
  • Get the index of a certain value in an array in PHP
  • How to update Python?
  • javascript compare strings without being case sensitive
  • How to use Regular Expressions (Regex) in Microsoft…
  • run function with uniquie value using javascript / node js
  • Spring boot - Not a managed type
  • How do the PHP equality (== double equals) and…
  • Can't remove element from dictionary
  • Equals(=) vs. LIKE
  • Postman gives 401 Unauthorized - Spring Boot & MYSQL
  • What does "SyntaxError: Missing parentheses in call…

Disclaimer: This content is shared under creative common license cc-by-sa 3.0. It is generated from StackExchange Website Network.

Post navigation

Previous Post:

Unable to find valid certification path to requested target – error even after cert imported

Next Post:

How can I generate random alphanumeric strings?

Leave a Reply Cancel reply

Your email address will not be published. Required fields are marked *

.net ajax android angular arrays aurelia backbone.js bash c++ css dataframe ember-data ember.js excel git html ios java javascript jquery json laravel linux list mysql next.js node.js pandas php polymer polymer-1.0 python python-3.x r reactjs regex sql sql-server string svelte typescript vue-component vue.js vuejs2 vuetify.js

  • you shouldn’t need to use z-index
  • No column in target database, but getting “The schema update is terminating because data loss might occur”
  • Angular – expected call-signature: ‘changePassword’ to have a typedeftslint(typedef)
  • trying to implement NativeAdFactory imports deprecated method by default in flutter java project
  • What should I use to get an attribute out of my foreign table in Laravel?
© 2022 Fix Code Error