ipartition¶
- iteration_utilities.ipartition(iterable, pred)¶
Use a predicate to partition entries into
False
entries andTrue
entries.- Parameters:
- iterableiterable
Iterable to partition.
- predcallable or None
The predicate which determines the group in which the value of the iterable belongs. If
None
it will usebool
to determine the truth-value of the items.
- Returns:
- false_valuesgenerator
An iterable containing the values for which the predicate was False.
- true_valuesgenerator
An iterable containing the values for which the predicate was True.
Examples
>>> from iteration_utilities import ipartition >>> def is_odd(val): return val % 2 >>> [list(i) for i in ipartition(range(10), is_odd)] [[0, 2, 4, 6, 8], [1, 3, 5, 7, 9]]