fnfor each element.
fnreturns a truthy value for any element, add it to the first group, otherwise add it to the second group.
def bifurcate_by(lst, fn): return [ [x for x in lst if fn(x)], [x for x in lst if not fn(x)] ]
bifurcate_by(['beep', 'boop', 'foo', 'bar'], lambda x: x == 'b') # [ ['beep', 'boop', 'bar'], ['foo'] ]
Subscribe to get resources directly to your inbox. You won't receive any spam! ✌️