Is there a way to make a list comprehension to search for a string being case insensitive?
What I do now, which is subpar is:
original_list = ['NAME', 'NUMBER', 'name', 'number', 'Name', 'NaMe', 'place']
filtered_list = [x for x in LIST if "NAME" in x or "name" in x]
This example would exclude "Name" and "NaMe" (which I want to be included) for example. The idea is to use a list comprehension and have a short and concise way of doing this.
I would like to do something like this:
case_insensitive_list = [x for x in LIST if 'name'.caseinsensitive() in x]
(it seems after the second OR the list comprehension begins to behave weird.)
I CANNOT use the str.upper() strategy, I need to retain the case of the original list.
I am expecting a simple list comprehension with a case agnostic string matching condition.
My expected outcome:
['NAME', 'name', 'Name', 'NaMe']