Say you have some list L
and you want to split it into two lists based on some boolean function P
. That is, you want one list of all the elements l
where P(l)
is true and another list where P(l)
is false.
I can implement this in Python like so:
def multifilter(pred,seq):
trues,falses = [],[]
for x in seq:
if pred(x):
trues.append(x)
else:
falses.append(x)
return trues,falses
My question: Is there a functional programming idiom that accomplishes this?