How to check if a string is in a list of strings, ignoring case, in Python

A string is in a list of strings if there is an element of the list of strings that matches the string character for character. Case insensitive string comparison ignores capitalization of characters.

Solution for How to check if a string is in a list of strings, ignoring case, in Python : You can use the in operator with the str.lower() function and a generator expression to check if a string is in a list of strings First, call str.lower() on the target string target_string to lowercase its characters. Then, use the in operator with the previous result as the left operand and the right operand as the generator expression (string.lower() for string in list_of_strings) which lowercases each string in the list_of_strings to get a boolean expression that represents the existence of the target string in list_of_strings, case insensitively.


how-to-check-if-a-string-is-in-a-list-of-strings-ignoring-case-in-python