# Bifurcate list based on values

Python, List · Nov 2, 2020

Splits values into two groups, based on the result of the given `filter` list.

• 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.
```def bifurcate(lst, filter):
return [
[x for x, flag in zip(lst, filter) if flag],
[x for x, flag in zip(lst, filter) if not flag]
]```
```bifurcate(['beep', 'boop', 'foo', 'bar'], [True, True, False, True])
# [ ['beep', 'boop', 'bar'], ['foo'] ]```

## More like this

• ### Bifurcate list based on function

Splits values into two groups, based on the result of the given filtering function.

Python, List · Nov 2, 2020

• ### List difference based on function

Returns the difference between two lists, after applying the provided function to each list element of both.

Python, List · Nov 2, 2020

• ### List symmetric difference based on function

Returns the symmetric difference between two lists, after applying the provided function to each list element of both.

Python, List · Nov 2, 2020