Groups | Search | Server Info | Keyboard shortcuts | Login | Register [http] [https] [nntp] [nntps]


Groups > comp.lang.python > #40933

Re: itertools.filterfalse - what is it good for

From Terry Reedy <tjreedy@udel.edu>
Subject Re: itertools.filterfalse - what is it good for
Date 2013-03-09 00:57 -0500
References <loom.20130308T173252-234@post.gmane.org>
Newsgroups comp.lang.python
Message-ID <mailman.3117.1362808661.2939.python-list@python.org> (permalink)

Show all headers | View raw


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

Back to comp.lang.python | Previous | Next | Find similar | Unroll thread


Thread

Re: itertools.filterfalse - what is it good for Terry Reedy <tjreedy@udel.edu> - 2013-03-09 00:57 -0500

csiph-web