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


Groups > comp.lang.python > #40973

Re: itertools.filterfalse - what is it good for

X-Received by 10.224.185.201 with SMTP id cp9mr4767236qab.6.1362861012753; Sat, 09 Mar 2013 12:30:12 -0800 (PST)
X-Received by 10.50.163.41 with SMTP id yf9mr383698igb.3.1362861012495; Sat, 09 Mar 2013 12:30:12 -0800 (PST)
Path csiph.com!v102.xanadu-bbs.net!xanadu-bbs.net!news.glorb.com!t2no234665qal.0!news-out.google.com!o5ni262qas.0!nntp.google.com!t2no234659qal.0!postnews.google.com!glegroupsg2000goo.googlegroups.com!not-for-mail
Newsgroups comp.lang.python
Date Sat, 9 Mar 2013 12:30:11 -0800 (PST)
In-Reply-To <mailman.3087.1362761126.2939.python-list@python.org>
Complaints-To groups-abuse@google.com
Injection-Info glegroupsg2000goo.googlegroups.com; posting-host=75.82.8.111; posting-account=uo-8fwoAAACKsFzFX78JHudx1V7WDXZ0
NNTP-Posting-Host 75.82.8.111
References <mailman.3087.1362761126.2939.python-list@python.org>
User-Agent G2/1.0
MIME-Version 1.0
Message-ID <ac6c2230-1b7a-4e73-a20a-4aa52dafbded@googlegroups.com> (permalink)
Subject Re: itertools.filterfalse - what is it good for
From Miki Tebeka <miki.tebeka@gmail.com>
Cc python-list@python.org
Injection-Date Sat, 09 Mar 2013 20:30:12 +0000
Content-Type text/plain; charset=ISO-8859-1
Xref csiph.com comp.lang.python:40973

Show key headers only | View raw


> can anybody point out a situation where you really need itertools.filterfalse() ?
Sometimes you get the predicate as a parameter to another function. This way if you want to filter out things you can easily do it. Other language (such as Clojure) have a "complement" function that removes the need of filterfalse.

For example (Python 3):
    def percent_spam(is_spam, documents):
        n_spam = sum(1 for _ in filter(is_spam, documents))
        n_ham = sum(1 for _ in filterfalse(is_spam, documents))
        return float(n_spam) / (n_ham + n_spam)

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


Thread

itertools.filterfalse - what is it good for Wolfgang Maier <wolfgang.maier@biologie.uni-freiburg.de> - 2013-03-08 16:45 +0000
  Re: itertools.filterfalse - what is it good for Neil Cerutti <neilc@norwich.edu> - 2013-03-08 17:02 +0000
  Re: itertools.filterfalse - what is it good for Miki Tebeka <miki.tebeka@gmail.com> - 2013-03-09 12:30 -0800
  Re: itertools.filterfalse - what is it good for Miki Tebeka <miki.tebeka@gmail.com> - 2013-03-09 12:30 -0800

csiph-web