It’s easy to implement in Python:
# An implementation of partition for Python
def partition(l, pred):
yes, no = , 
for e in l:
return yes, no
And it’s easy to test:
return (n % 2) == 1
odd, even = partition(range(10), is_odd)
odd, even = partition([1,3,5], is_odd)
odd, even = partition([2,4,6], is_odd)
odd, even = partition(, is_odd)
if __name__ == '__main__':
I also wondered about generalizations: take a function returning a small integer, and return a list where the i’th element is a list of all the values for which the function return i? Or return a dictionary whose keys are the values returned by the function, and the values are lists of input values that caused them? I imagine different cases could be made for either of these.
I don’t have a use for any of this at the moment, just an idle mental exercise.