Skip to content

Home

List intersection

Returns a list of elements that exist in both lists.

def intersection(a, b):
  _a, _b = set(a), set(b)
  return list(_a & _b)

intersection([1, 2, 3], [4, 3, 2]) # [2, 3]

More like this

Start typing a keyphrase to see matching snippets.