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 between map() and itertools.starmap().

New in version 0.3.

Parameters:

pred : callable

The predicate function that is called to determine if the items should be kept.

Note

Unlike filter() the pred cannot be None.

iterable : iterable

Iterable containing the elements.

Returns:

iterator : generator

A normal iterator over iterable containing only the items where pred(*item) is True.

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.