if any element in list is in another list python code example
Example 1: check if a list contains an item from another list python
list_A = [1, 2, 3, 4]
list_B = [2, 3, 6]
check = any(item in list_A for item in list_B)
print(check)
Example 2: python check list contains another list
>>> items = set([-1, 0, 1, 2])
>>> set([1, 2]).issubset(items)
True
>>> set([1, 3]).issubset(items)
False
Example 3: python check if list contains elements of another list
list_A = [1, 2, 3, 4]
list_B = [2, 3]
check = all(item in list_A for item in list_B)
print(check)
Example 4: how to check if any item in list is in anoter list
list_A = [1, 2, 3, 4]
list_B = [2, 3]
check = any(item in list_A for item in list_B)
print(check)
Example 5: check if a list contains any item from another list python
list_A = [1, 2, 3, 4]
list_B = [5,1]
set_A = set(list_A)
set_B = set(list_B)
output = False if (set_A.intersection(set_B) == set()) else True
print(output)