Check if a Value Exists in a List Using Python (Case Insensitive)

preview_player
Показать описание
Check if a Value Exists in a List Using Python (Case Insensitive)

Greetings, today we are going to look at how to do a lookup check in Python that is case insensitive. A lookup check is a code check validation tequnique. We will be checking if a certain value is in an array/list. A case insensitive lookup check is where we don't care about the case.

Eg: "mOnDay" is the input and we have a value of "Monday" in our list. Normally, this would be false as "mOnDay" isn't equal to "Monday", but if we ignore the casing, these 2 values are equal.

This can be useful for situations where there are certain inputs you want from the user, such as a City or a day of the week. There are a finite amount of valid inputs for these values.

We can check if a value/element is in a list by using the 'in' keyword. We also need to use a loop to itterate through each element of the list and convert the current element we are checking to be lower case and to convert the input to lower case. This evens the playing field and means Python won't factor in the case of the input and list element when do a comparison.

If your array/list has duplicate values, the match will be found on the 1st instance of the duplicate value.

Thanks for watching this validation tutorial on how to do a lookup check on a list using Python.

Check if a Value Exists in a List Using Python (Case Insensitive)
Рекомендации по теме