for a list of lists, the most efficient way is to use:
result = set(list1).intersection(list2)
as mentioned, but for numpy arrays the intersection1d function is more efficient:
import numpy as np result = np.intersection1d(list1, list2)
In particular, when you know that lists have no duplicate values, you can use it like:
result = np.intersection1d(list1, list2, assume_unique=True)
source share