partition

iteration_utilities.partition(iterable, pred=None)

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

Parameters:

iterable : iterable

Iterable to partition.

pred : callable or None, optional

The predicate which determines the partition. Default is None.

Returns:

false_values : list

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

true_values : list

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 noticable faster than ipartition().