python elements of list isin another list code example
Example 1: 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 2: 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 3: check if part of list is in another list python
'''
check if list1 contains any elements of list2
'''
result = any(elem in list1 for elem in list2)
if result:
print("Yes, list1 contains any elements of list2")
else :
print("No, list1 contains any elements of list2")