Files
30-seconds-of-code/snippets/is_contained_in.md
Angelos Chalaris 82d99f98cb Apply suggestions from code review
Co-Authored-By: Isabelle Viktoria Maciohsek <maciv@hotmail.gr>
2020-03-16 22:00:46 +02:00

23 lines
524 B
Markdown

---
title: is_contained_in
tags: list,intermediate
---
Returns `True` if the elements of the first list are contained in the second one regardless of order, `False` otherwise.
Use `count()` to check if any value in `a` has more occurences than it has in `b`, returning `False` if any such value is found, `True` otherwise.
```py
def is_contained_in(a, b):
for v in set(a):
if a.count(v) > b.count(v):
return False
return True
```
```py
is_contained_in([1, 4], [2, 4, 1]) # True
```