Re: itertools.filterfalse - what is it good for

Discussion in 'Python' started by Terry Reedy, Mar 9, 2013.

  1. Terry Reedy

    Terry Reedy Guest

    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
     
    Terry Reedy, Mar 9, 2013
    #1
    1. Advertising

Want to reply to this thread or ask your own question?

It takes just 2 minutes to sign up (and it's free!). Just click the sign up button to choose a username and then you can ask your own questions on the forum.
Similar Threads
  1. Replies:
    0
    Views:
    893
  2. Steven Bethard
    Replies:
    0
    Views:
    410
    Steven Bethard
    Mar 12, 2005
  3. Raymond Hettinger
    Replies:
    17
    Views:
    567
    Simon Brunning
    Feb 18, 2008
  4. Nick Mellor
    Replies:
    35
    Views:
    387
    Paul Rubin
    Dec 6, 2012
  5. Wolfgang Maier

    itertools.filterfalse - what is it good for

    Wolfgang Maier, Mar 8, 2013, in forum: Python
    Replies:
    3
    Views:
    146
    Miki Tebeka
    Mar 9, 2013
Loading...

Share This Page