Is this a good use for lambda

Fredrik Lundh fredrik at
Mon Dec 20 00:45:39 CET 2004

Simo Melenius wrote:

>> Ahem. If you name the function, you can reuse the name (or just
>> forget about it) as soon as you've used the function object.
> Sure, but mental pollution counts too IMO. What you write and what you
> read must go through your brain, including dummy variables. And next
> you start thinking how to "hide" it from your own mind (e.g. naming it
> "_my_local_func" or something as ugly as the leading underscores in
> it).

use something short, like "f".  hopefully, a single character won't overload
your brain.

> And I think that it does, in fact, touch the innermost symbol table
> too, even if the case is optimized out by the compiler -- is it?

yes, but the overhead of keeping a local slot updated is very small,
especially compared to all the work Python's doing to create a new
function object.

(or did you mean that you're trying to keep the entire symbol table
in your head?  I think my point was that you don't really have to do
that; just concentrate on what's close to the code you're reading)

> Why do something for the sake of not actually having to do it?

not sure I parsed that one correctly, but when I name functions, I usually
do that because it makes my code cleaner, more self-describing, gives it
a better visual layout, makes it easier to modify/maintain, makes it easier
to set breakpoints or add debugging statements, etc.  "lambda blocks"
can address some of that, but not all of it.


More information about the Python-list mailing list