QuickSnip LogoA light blue logo with a thunderbolt in bracketsQuickSnip

Find Intersection of Two Lists

Finds the common elements between two lists.

  • list
  • intersection

Code

def list_intersection(lst1, lst2):
    return [item for item in lst1 if item in lst2]

Usage

list_a = [1, 2, 3, 4]
list_b = [3, 4, 5, 6]
list_intersection(list_a, list_b) # Returns: [3, 4]