count()
to check if any value in a
has more occurrences than it has in b
.False
if any such value is found, True
otherwise.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
Subscribe to get resources directly to your inbox. You won't receive any spam! ✌️