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


Groups > comp.lang.python > #40974

Re: itertools.filterfalse - what is it good for

Newsgroups comp.lang.python
Date 2013-03-09 12:30 -0800
References <mailman.3087.1362761126.2939.python-list@python.org>
Subject Re: itertools.filterfalse - what is it good for
From Miki Tebeka <miki.tebeka@gmail.com>
Message-ID <mailman.3139.1362861020.2939.python-list@python.org> (permalink)

Show all headers | 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 | 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