Use sets:
>>> a = [1, 2, 3, 4] >>> b = [2, 3, 4, 5] >>> c = [3, 4, 5, 6] >>> set(a) & set(b) & set(c) {3, 4}
Or, as John suggested:
>>> set(a).intersection(b, c) {3, 4}
Using sets has the advantage that you do not need to repeat the original lists. Each list is repeated once to create sets, and then sets intersect.
A naive way to solve this problem using a filtered list, as Geotob did, would result in repeating lists b and c for each element a , so this would be much less efficient for a longer list.
source share