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
| Name | Type | Description |
|---|---|---|
| predicate | callable | A function that accepts an item and returns a boolean value used to determine which set the item belongs to. |
| values | iterable | A collection of items to be partitioned into two separate lists based on the predicate result. |
Returns
| Type | Description |
|---|---|
tuple | A 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. |