Python – simple way to join 2 arrays/lists based on common values

arraysnumpypython

I have tried for a while but can't find a simple way to join 2 lists or arrays based only on common values. Similar to an SQL inner join but with arrays/lists and not dict, or some other data type. eg.

a = [1, 2, 3]
b = [2, 3, 4]
join(a, b)

prints

[2, 3]

seems so simple but lacking from python or numpy.

Best Solution

Probably a duplicate, but in case it is not:

>>> a = [1,2,3]
>>> b = [2,3,4]
>>> list(set(a) & set(b))
[2, 3]

For large lists (external data), see this S.O. answer.