Python if any in list is checks for any element satisfying a condition and returns a True in case it finds any one element.
Python if any in the list example
Simple example code Check if any element in list satisfies a condition using any() function.
aList = [4, 2, 3, 1, 5, 6]
res = any(ele > 10 for ele in aList)
If you only want to check the existence of one element in a list use in operator.
a = [4, 2, 3, 1, 5, 6]
print(7 in a)
is the fastest solution. Note though that
7 in set_data
Do comment if you have any doubts or suggestions on this Python any() function topic.
Note: IDE: PyCharm 2021.3.3 (Community Edition)
All Python Examples are in Python 3, so Maybe its different from python 2 or upgraded versions.