1def intersection(lst1, lst2):
2 lst3 = [value for value in lst1 if value in lst2]
3 return lst3
4
5# Driver Code
6lst1 = [4, 9, 1, 17, 11, 26, 28, 54, 69]
7lst2 = [9, 9, 74, 21, 45, 11, 63, 28, 26]
8print(intersection(lst1, lst2))
1import numpy as np
2recent_coding_books = np.intersect1d(recent_books,coding_books)
1# intersection of two lists (lst1 & lst2)
2In [1]: x = ["a", "b", "c", "d", "e"]
3
4In [2]: y = ["f", "g", "h", "c", "d"]
5
6In [3]: set(x).intersection(y)
7Out[3]: {'c', 'd'}
8# has_intersection = bool(set(x).intersection(y)) -> True
1# Python program to illustrate the intersection
2# of two lists in most simple way
3def intersection(lst1, lst2):
4 lst3 = [value for value in lst1 if value in lst2]
5 return lst3
6
7# Driver Code
8lst1 = [4, 9, 1, 17, 11, 26, 28, 54, 69]
9lst2 = [9, 9, 74, 21, 45, 11, 63, 28, 26]
10print(intersection(lst1, lst2))
11
1# 3 Approaches to find intersect of two lists:
2# set two lists:
3a = [1,2,3,4,5,6,7,8]
4b = [8,7,4,3,100,200]
5# the intersect c should be [3,4,7,8]
6# Method 1:
7c = list(set(a) & set(b))
8print(c)
9# Method 2:
10c = list(filter(set(a).__contains__, b))
11print(c)
12# Method 3:
13c = list(set(a).intersection(b))