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

Path csiph.com!newsfeed.hal-mli.net!feeder3.hal-mli.net!newsfeed.hal-mli.net!feeder2.hal-mli.net!us.feeder.erje.net!feeder.erje.net!eu.feeder.erje.net!newsfeed.freenet.ag!news2.euro.net!newsgate.cistron.nl!newsgate.news.xs4all.nl!post.news.xs4all.nl!not-for-mail
Return-Path <python-python-list@m.gmane.org>
X-Original-To python-list@python.org
Delivered-To python-list@mail.python.org
X-Spam-Status OK 0.001
X-Spam-Evidence '*H*': 1.00; '*S*': 0.00; 'true,': 0.04; 'e.g.,': 0.07; 'type,': 0.07; 'here?': 0.09; 'received:80.91': 0.09; 'received:80.91.229': 0.09; 'received:gmane.org': 0.09; 'received:list': 0.09; 'terry': 0.09; 'expressions.': 0.16; 'iterator': 0.16; 'itertools': 0.16; 'reason?': 0.16; 'received:80.91.229.3': 0.16; 'received:plane.gmane.org': 0.16; 'reedy': 0.16; 'wrote:': 0.17; 'exists': 0.17; 'jan': 0.18; 'versions': 0.20; 'all,': 0.21; 'meant': 0.21; 'together.': 0.21; 'header:In-Reply-To:1': 0.25; 'header:User-Agent:1': 0.26; 'am,': 0.27; 'replace': 0.27; 'header:X-Complaints-To:1': 0.28; 'far,': 0.29; 'subject:what': 0.29; 'function': 0.30; 'point': 0.31; 'anybody': 0.32; 'achieving': 0.33; 'defining': 0.33; 'function.': 0.33; 'to:addr:python-list': 0.33; 'built-in': 0.35; 'filter': 0.35; 'replaced': 0.35; 'list.': 0.35; 'received:org': 0.36; 'really': 0.36; 'but': 0.36; 'functional': 0.36; 'subject:: ': 0.38; 'object': 0.38; 'sure': 0.38; 'instead': 0.39; 'to:addr:python.org': 0.39; 'where': 0.40; 'header:Received:5': 0.40; 'think': 0.40; 'situation': 0.62; 'dear': 0.66; 'believe': 0.69; '11:45': 0.84; 'received:fios.verizon.net': 0.84; 'subject:good': 0.84
X-Injected-Via-Gmane http://gmane.org/
To python-list@python.org
From Terry Reedy <tjreedy@udel.edu>
Subject Re: itertools.filterfalse - what is it good for
Date Sat, 09 Mar 2013 00:57:16 -0500
References <loom.20130308T173252-234@post.gmane.org>
Mime-Version 1.0
Content-Type text/plain; charset=UTF-8; format=flowed
Content-Transfer-Encoding 7bit
X-Gmane-NNTP-Posting-Host pool-173-75-251-66.phlapa.fios.verizon.net
User-Agent Mozilla/5.0 (Windows NT 6.1; WOW64; rv:17.0) Gecko/20130215 Thunderbird/17.0.3
In-Reply-To <loom.20130308T173252-234@post.gmane.org>
X-BeenThere python-list@python.org
X-Mailman-Version 2.1.15
Precedence list
List-Id General discussion list for the Python programming language <python-list.python.org>
List-Unsubscribe <http://mail.python.org/mailman/options/python-list>, <mailto:python-list-request@python.org?subject=unsubscribe>
List-Archive <http://mail.python.org/pipermail/python-list/>
List-Post <mailto:python-list@python.org>
List-Help <mailto:python-list-request@python.org?subject=help>
List-Subscribe <http://mail.python.org/mailman/listinfo/python-list>, <mailto:python-list-request@python.org?subject=subscribe>
Newsgroups comp.lang.python
Message-ID <mailman.3117.1362808661.2939.python-list@python.org> (permalink)
Lines 23
NNTP-Posting-Host 2001:888:2000:d::a6
X-Trace 1362808661 news.xs4all.nl 6890 [2001:888:2000:d::a6]:57889
X-Complaints-To abuse@xs4all.nl
Xref csiph.com comp.lang.python:40933

Show key headers only | 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