intersection of two lists python
>>> a = [1,2,3,4,5]
>>> b = [1,3,5,6]
>>> list(set(a) & set(b))
[1, 3, 5]
intersection of two lists python
>>> a = [1,2,3,4,5]
>>> b = [1,3,5,6]
>>> list(set(a) & set(b))
[1, 3, 5]
python get the intersection of two lists
# intersection of two lists (lst1 & lst2)
In [1]: x = ["a", "b", "c", "d", "e"]
In [2]: y = ["f", "g", "h", "c", "d"]
In [3]: set(x).intersection(y)
Out[3]: {'c', 'd'}
# has_intersection = bool(set(x).intersection(y)) -> True
intersection of 3 array in O(n) python
def intersection(A, B, C):
'''
Intersection of 3 array in O(n).
'''
i = j = k = 0
len1 = len(A)
len2 = len(B)
len3 = len(C)
while (i < len1 and j < len2 and k< len3):
if (A[i] == B[j] and B[j] == C[k]):
print(A[i])
i += 1
j += 1
k += 1
elif A[i] < B[j]:
i += 1
elif B[j] < C[k]:
j += 1
else:
k += 1
Copyright © 2021 Codeinu
Forgot your account's password or having trouble logging into your Account? Don't worry, we'll help you to get back your account. Enter your email address and we'll send you a recovery link to reset your password. If you are experiencing problems resetting your password contact us