itertools.filterfalse - what is it good for
Terry Reedy
tjreedy at udel.edu
Sat Mar 9 00:57:16 EST 2013
On 3/8/2013 11:45 AM, Wolfgang Maier wrote:
> Dear all,
> can anybody point out a situation where you really need itertools.filterfalse() ?
> So far, I couldn't think of a case where you couldn't replace it with a
> generator expression/if combination.
> e.g.,
>
> a=filterfalse(lambda x: x%2, range(1,101))
> b=(i for i in range(1,101) if not i % 2)
>
> do not return the same object type, but otherwise are achieving the same thing.
> What am I missing here? For sure filterfalse exists for a reason?
I believe itertools existed before generator expressions. They are meant
to work together. filterfalse is the complement of iterator filter on
True, which was in itertools before it replaced the old built-in filter
that return a list. All of the functional versions work best is you
already have a function instead of defining one in place. The
comprehension works best if one has just an expression and not a function.
--
Terry Jan Reedy
More information about the Python-list
mailing list