Skip to content

Home

List is contained in other list

Checks if the elements of the first list are contained in the second one regardless of order.

def is_contained_in(a, b):
  for v in set(a):
    if a.count(v) > b.count(v):
      return False
  return True

is_contained_in([1, 4], [2, 4, 1]) # True

More like this

Start typing a keyphrase to see matching snippets.