Help With filter().

Alex Martelli aleaxit at
Thu Jul 12 04:48:11 EDT 2001

"EricIDLE" <grayson-wilson at> wrote in message
news:XA537.678643$166.13965187 at
> What does filter do? I don't understand when I read it other places.

Would you understand the following pure Python function...:

    return [item for item in sequence if function(item)]

or its more verbose equivalent...:

def filter2(function, sequence):
    result = []
    for item in sequence:
        if function(item):
    return result

If you understand this, it's very easy to explain the
semantics of builtin filter by difference from those
of these pure-Python filter1 and filter2 -- the
differences are not many, nor are they complex.

If you don't understand these pure-Python functions,
then we'd better focus on this, and wait for filter
when you have a better grasp of fundamentals...?


More information about the Python-list mailing list