1## checking any elment of list_B in list_A
2list_A = [1, 2, 3, 4]
3
4list_B = [2, 3, 6]
5
6check = any(item in list_A for item in list_B)
7
8print(check)
9# True
1>>> items = set([-1, 0, 1, 2])
2>>> set([1, 2]).issubset(items)
3True
4>>> set([1, 3]).issubset(items)
5False
6
1'''
2 check if list1 contains any elements of list2
3'''
4result = any(elem in list1 for elem in list2)
5if result:
6 print("Yes, list1 contains any elements of list2")
7else :
8 print("No, list1 contains any elements of list2")
1## using set
2list_A = [1, 2, 3, 4]
3list_B = [2, 3]
4
5set_A = set(list_A)
6set_B = set(list_B)
7
8print(set_A.intersection(set_B))
9
10# True if there is any element same
11# False if there is no element same