Update snippet descriptions

This commit is contained in:
Isabelle Viktoria Maciohsek
2020-11-02 19:27:07 +02:00
parent c469b67f0b
commit a2cd6db3b0
22 changed files with 67 additions and 64 deletions

View File

@ -3,10 +3,10 @@ title: bifurcate
tags: list,intermediate
---
Splits values into two groups.
If an element in `filter` is `True`, the corresponding element in the collection belongs to the first group; otherwise, it belongs to the second group.
Splits values into two groups, based on the result of the given `filter` list.
- Use list comprehension and `zip()` to add elements to groups, based on `filter`.
- Use a list comprehension and `zip()` to add elements to groups, based on `filter`.
- If `filter` has a truthy value for any element, add it to the first group, otherwise add it to the second group.
```py
def bifurcate(lst, filter):
@ -17,5 +17,6 @@ def bifurcate(lst, filter):
```
```py
bifurcate(['beep', 'boop', 'foo', 'bar'], [True, True, False, True]) # [ ['beep', 'boop', 'bar'], ['foo'] ]
bifurcate(['beep', 'boop', 'foo', 'bar'], [True, True, False, True])
# [ ['beep', 'boop', 'bar'], ['foo'] ]
```