username = 'MICHAEL89'
if username.upper() in (name.upper() for name in USERNAMES):
    ...

Alternatively:

if username.upper() in map(str.upper, USERNAMES):
    ...

Or, yes, you can make a custom method.

Answer from nmichaels on Stack Overflow
๐ŸŒ
GeeksforGeeks
geeksforgeeks.org โ€บ python โ€บ case-insensitive-string-comparison-in-python
Case-insensitive string comparison in Python - GeeksforGeeks
July 15, 2025 - It converts all strings, checks uniqueness using a set and prints "equal" if all are identical otherwise, "unequal". re.match() checks if a string matches a pattern from the start and with the re.IGNORECASE flag, it ignores case differences.
๐ŸŒ
Reddit
reddit.com โ€บ r/learnprogramming โ€บ need help with case insensitive list comparison in python
r/learnprogramming on Reddit: Need help with case insensitive list comparison in Python
August 26, 2019 -

Hi all,

I'm learning python and have been trying to figure out how to properly compare lists for case insensitivity. If I have two lists, where the first list contains the current user names and the second list is a list of new usernames, how do I get to make sure that if a new user name John won't conflict with a username in the current users of JoHn or JOHN and vice versa?

I have this so far:

current_users = ['John', 'BiLl', 'simcitizzon', 'mIke', 'cHarlie', 'admin']

new_users = ['john', 'simcitiZzon', 'ralphwiggum', 'cherrymcsperry', 'sweettooth347']

for user in new_users:
    if user in current_users:
	    print("Sorry, " + user + " is taken.")
    else:
	    print(user + ", this username is available")
๐ŸŒ
Finxter
blog.finxter.com โ€บ home โ€บ learn python blog โ€บ how to ignore case in python strings
How to Ignore Case in Python Strings - Be on the Right Side of Change
August 25, 2022 - This article outlines various ways to ignore the case of Strings. ๐Ÿ’ฌ Question: How would we write code to compare Strings? We can accomplish this task by one of the following options: ... This method uses lower() and a lambda to convert a List of Strings to lower case to search for an Employee.
๐ŸŒ
Reddit
reddit.com โ€บ r/learnpython โ€บ trying to create case-insensitive user search for list, but '.lower()' method isn't working, any help please?
r/learnpython on Reddit: Trying to create case-insensitive user search for list, but '.lower()' method isn't working, any help please?
October 30, 2019 -

Here is the relevant section of code as I originally wrote it:

  elif choice == "4":
      print('What would you like to find? ')
      search_item = input()
      if search_item not in thislist:
          print ("Not found in this list:")
      else:
          print ("Found in this list:")
      print(', '.join(thislist))

...but it turned out that this was case-sensitive to user input, which is not desired, so I tried...

  elif choice == "4":
      print('What would you like to find? ')
      search_item = input()
      if (search_item.lower() not in thislist.lower()):
          print ("Not found in this list:")
      else:
          print ("Found in this list:")
      print(', '.join(thislist))

...as mentioned, for instance here. But it doesn't work, and I get...

Traceback (most recent call last): File "main.py", line 39, in <module> if (search_item.lower() not in thislist.lower()): AttributeError: 'list' object has no attribute 'lower'

I'm guessing that maybe it's because one or both of these isn't a string, but I'm not sure how to fix that if that is really the problem. Any help please? TIA.

BTW, I'm using https://repl.it, as I don't have a Python IDE installed on my home PC.

๐ŸŒ
Mathspp
mathspp.com โ€บ blog โ€บ how-to-work-with-case-insensitive-strings
How to work with case-insensitive strings | mathspp
January 21, 2023 - The method str.casefold is the method that you want to use when you need to do caseless, or case-insensitive, comparisons in Python.
Find elsewhere
๐ŸŒ
Peterbe.com
peterbe.com โ€บ plog โ€บ case-insensitive-list-remove-call
Case insensitive list remove call - Peterbe.com
April 10, 2006 - The following (based on a guess about how list.remove() might work) is perhaps a nicer solution: class CaseInsensitiveString(object): ... def __init__(self, s): ....... self.s = s ... def __cmp__(self, other): .......
๐ŸŒ
GeeksforGeeks
geeksforgeeks.org โ€บ python โ€บ python-ways-to-sort-list-of-strings-in-case-insensitive-manner
Python - Ways to sort list of strings in case-insensitive manner - GeeksforGeeks
July 12, 2025 - Key=str.lower ensures case-insensitive sorting by converting each string to lowercase for comparison, resulting in ['Apple', 'banana', 'cherry'].
๐ŸŒ
LearnPython.com
learnpython.com โ€บ blog โ€บ python-case-sensitive
Is Python Case-Sensitive? | LearnPython.com
Avoid confusion in your code by using consistent naming conventions and by avoiding names that are hard to distinguish from one another (like the uppercase letter 'I' and the lowercase 'l'). Use descriptive names but keep them as short as possible.
๐ŸŒ
TutorialsPoint
tutorialspoint.com โ€บ article โ€บ case-insensitive-string-replacement-using-python-program
Case-insensitive string replacement using Python Program
January 27, 2023 - input_string = "Hello TutorialsPOINT ... = " ".join(result_words) print("Result:", result) ... Use re.sub() with (?i) flag for simple case-insensitive replacements. For complex patterns or multiple operations, re.compile() with ...
๐ŸŒ
Reddit
reddit.com โ€บ r/learnprogramming โ€บ python question: comparing lists, case insensitive
r/learnprogramming on Reddit: python question: comparing lists, case insensitive
August 2, 2017 -

Hi everyone, I am just starting to learn how to code, running into a problem when I try to compare two lists, my code is below:

current_users = ['May', 'April', 'Wu', 'Su', 'Lulu'] new_users = ['may', 'mike', 'jones', 'chow', 'paul'] for new_user in new_users: if new_user in current_users: print('username '+new_user+' is not available.') else: print('welcome')

when I try to make the current_users list case insensitive for comparing, I used:

current_users.lower() ==['may', 'april', 'wu', 'su', 'lulu']

when I run the code, result in a violation, stated that list can not have contribute .lower().

Is there anyway to make the list case insensitive?

thanks in advance.

๐ŸŒ
GeeksforGeeks
geeksforgeeks.org โ€บ python โ€บ python-case-insensitive-string-replacement
Case insensitive string replacement in Python - GeeksforGeeks
July 23, 2025 - Python ยท import re a = "gfg is ... of the word "best" in string a with "good", ignoring case sensitivity by using the re.IGNORECASE flag and returns the modified string....
๐ŸŒ
EyeHunts
tutorial.eyehunts.com โ€บ home โ€บ python string contains case insensitive | example code
Python string contains case insensitive | Example code
April 25, 2022 - Use the in operator with the lower() or upper() function and a generator expression to check if a string is in a list of strings to check the string contains case insensitive in Python.
๐ŸŒ
Sololearn
sololearn.com โ€บ en โ€บ Discuss โ€บ 1254102 โ€บ how-to-make-python-case-insensitive
How to make python case insensitive
May 3, 2018 - Sololearn is the world's largest community of people learning to code. With over 25 programming courses, choose from thousands of topics to learn how to code, brush up your programming knowledge, upskill your technical ability, or stay informed about the latest trends.