The Most Pythonic Way to Check If a List Contains an Element
The standard way of checking if an element exists in a list is to use the in keyword. For example, ‘Alice’ in [1, ‘Alice’, 3] will return True while the same returns False for ‘Bob’. If you need to check more complicated conditions, use the any(condition(x) for x in list) function with a generator expression. … Read more