partition

iteration_utilities.partition(iterable, pred=None)

Use a predicate to partition entries into False entries and True entries.

Parameters:
iterableiterable

Iterable to partition.

predcallable or None, optional

The predicate which determines the partition. Default is None.

Returns:
false_valueslist

An list containing the values for which the pred was False.

true_valueslist

An list containing the values for which the pred was True.

See also

ipartition

Generator variant of partition().

Examples

>>> from iteration_utilities import partition
>>> def is_odd(val): return val % 2
>>> partition(range(10), is_odd)
([0, 2, 4, 6, 8], [1, 3, 5, 7, 9])

Warning

In case the pred is expensive then partition() can be noticeable faster than ipartition().