A = ['a','b','c']
B = ['d','b','e']
res = [i for i in A if i in B]
The above code does not work when the no of elements in A are 300000 and in B are 200000.
How can I solve it?
I also tried
res = {i for i in A if i in B}
res = list(res)
But still could not get the result.
Bto a set first:B = set(B), then use the list comprehension.A = set(A)andB = set(B), then do the intersectionres = A & B?