Is this a good use for lambda
Michael Sparks
zathras at thwackety.com
Sun Dec 19 21:32:02 EST 2004
On Mon, 20 Dec 2004, Fredrik Lundh wrote:
> 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.
(for Simo)
If namespace pollution extends to single characters why not just use _ as
the function name. Even looks like a "null" name.
def _(arg): print arg
If they're intended as throwaways for sending to another function or
putting in a dict:
def _(arg): print arg
def __(arg): print arg
def ___(arg): print arg
def ____(arg): print arg
someMap = { "a": _, "a": __,"a": ___,"a": ____ }
(Though personally I can't see the harm in giving a temporary function a
name, much like you often give intermediary values in a function names)
Michael.
More information about the Python-list
mailing list