Splits values into two groups, based on the result of the given filter
list.
zip()
to add elements to groups, based on filter
.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'] ]
Python, List
Splits values into two groups, based on the result of the given filtering function.
Python, List
Groups the elements of a list based on the given function and returns the count of elements in each group.
Python, List
Groups the elements of a list based on the given function.