starfilter¶
- class iteration_utilities.starfilter(pred, iterable)¶
Like
filter()
but unpacks the current item in iterable when calling pred. This is similar to the difference betweenmap()
anditertools.starmap()
.New in version 0.3.
- Parameters:
- predcallable
The predicate function that is called to determine if the items should be kept.
Note
Unlike
filter()
the pred cannot beNone
.- iterableiterable
Iterable containing the elements.
- Returns:
- iteratorgenerator
A normal iterator over iterable containing only the items where
pred(*item)
isTrue
.
See also
Notes
This is identical to
filter(lambda x: pred(*x), iterable)
but faster.Examples
A simple example:
>>> from iteration_utilities import starfilter >>> from operator import eq >>> list(starfilter(eq, zip([1,2,3], [2,2,2]))) [(2, 2)]
- pred¶
(callable) The function by which to filter (readonly).
New in version 0.6.