There appear to be several ways to determine if a set is a subset of another set, but I haven't been able to find something concise that determines whether all elements of a list (or array), including duplicate values, appear in another list (or array). For example, for the hypothetical function contains_all(A, B) which checks whether all elements of B are contained in A, these are some expected outputs:
contains_all([11, 4, 11, 6], [6, 11]) returns True (order doesn't matter)
contains_all([11, 4, 11, 6], [11, 9]) returns False (no 9)
contains_all([11, 4, 11, 6], [11, 11]) returns True
contains_all([11, 4, 11, 6], [11, 11, 11]) returns False (only two 11's)
contains_all([11, 4, 11, 6], [6, 6]) returns False (only one 6)
contains_all([11, 4, 11, 6], [11, 4, 6, 11]) returns True
contains_all([11, 4, 11, 6], [11, 4, 11, 6, 5]) returns False (no 5)
The fourth and fifth examples above, specifically, are what I'm having trouble implementing. set(B).issubset(A) or list comprehensions cover the other cases, but not these, since sets don't have duplicate elements. Is there a concise way to do this? If not, what would be the best way to approach writing a function that does this? It seems something like this may be possible with collections.Counter objects or multisets, but I'm not sure how to go about it.