Add have_same_contents, includes_all and includes_any

This commit is contained in:
Isabelle Viktoria Maciohsek
2020-03-14 11:34:52 +02:00
committed by GitHub
parent b047b8f546
commit 53c0329a89
3 changed files with 64 additions and 0 deletions

21
includes_all.md Normal file
View File

@ -0,0 +1,21 @@
---
title: includes_all
tags: utility,intermediate
---
Returns `True` if all the elements in `values` are included in `lst`, `False` otherwise.
Check if every value in `values` is contained in `lst` using a `for` loop, returning `False` if any one value is not found, `True` otherwise.
```py
def includes_all(lst, values):
for v in values:
if v not in lst:
return False
return True
```
```py
includes_all([1, 2, 3, 4], [1, 4]) # True
includes_all([1, 2, 3, 4], [1, 5]) # False
```