Add have_same_contents, includes_all and includes_any
This commit is contained in:
committed by
GitHub
parent
b047b8f546
commit
53c0329a89
21
includes_any.md
Normal file
21
includes_any.md
Normal file
@ -0,0 +1,21 @@
|
||||
---
|
||||
title: includes_any
|
||||
tags: list,intermediate
|
||||
---
|
||||
|
||||
Returns `True` if any the elements in `values` are included in `lst`, `False` otherwise.
|
||||
|
||||
Check if any value in `values` is contained in `lst` using a `for` loop, returning `True` if any one value is found, `False` otherwise.
|
||||
|
||||
```py
|
||||
def includes_any(lst, values):
|
||||
for v in values:
|
||||
if v in lst:
|
||||
return True
|
||||
return False
|
||||
```
|
||||
|
||||
```py
|
||||
includes_any([1, 2, 3, 4], [2, 9]) # True
|
||||
includes_any([1, 2, 3, 4], [8, 9]) # False
|
||||
```
|
||||
Reference in New Issue
Block a user