Skip to main content

partition

Split the values into two sets, based on the return value of the function (True/False). e.g.:

> > > partition(lambda x: x > 3, range(5))
[0, 1, 2, 3], [4]
def partition(
predicate: callable,
values: iterable
) - > tuple

Split the values into two sets, based on the return value of the function (True/False).

Parameters

NameTypeDescription
predicatecallableA function that accepts an item and returns a boolean value used to determine which set the item belongs to.
valuesiterableA collection of items to be partitioned into two separate lists based on the predicate result.

Returns

TypeDescription
tupleA tuple containing two lists: the first list contains items where the predicate returned False, and the second list contains items where the predicate returned True.