[Tutor] map, filter and lambda functions [filter can take None]

Allan Crooks allan.crooks@btinternet.com
Sun, 26 Aug 2001 03:14:35 +0100


> > *Why* it works? Just because filter is designed to work that way.
> > Initially I was going to suggest a way of doing that, but instead of
> > None, I was going to suggest the truth function from the operator
> > module.
> > 
> > None certainly isn't a function though.
> 
> [Note: skip if you're not interested in looking at Python icky C
> internals.]
> 
> 
> Feeding 'None' as a "function" is a special case that's particular
> only to Python's implementation of filter(), that is, this is
> hardcoded to recognize this unusual input.  It certainly doesn't do it
> for a human-intuitive reason.  *grin*
> 
> If we're interested in looking at C code, we can glance at the
> relevant code in the 'bltinmodule.c' file under the function
> "builtin_filter()":

<snip>

And yet again, a question that could only be solved by looking at 
the C code is answered by Danny. Only he would wade through the 
source, make it understandable and explain it for us, so I'll take 
this opportunity to thank him for it. :)

And while I'm at it, I'll thank him for his explanation of how hashing 
works, as well as a request from a long time ago about what 
buffers were. Thank you very much Danny. :)

Oh, and I think you spend too much time looking through Python's 
source than can possibly be healthy, but I reckon you knew that 
already. :)))

Allan.