explain this function to me, lambda confusion
Terry Reedy
tjreedy at udel.edu
Mon May 19 00:22:24 EDT 2008
"Arnaud Delobelle" <arnodel at googlemail.com> wrote in message
news:m2ve1b7msb.fsf at googlemail.com...
| Lie <Lie.1296 at gmail.com> writes:
|
| > Lambda can actually be safely removed from python and no other
| > features would be missing. It is always possible to create a def
| > version of any lambda, so lambda is useless. It is just a convenience
| > for the times where we're just too lazy to invent a name and find a
| > place to place the def, instead just inlining the function.
|
| Note that the same thing can be said about generator expressions,
| which are nothing more than anonymous, non-reusable, generator
| functions.
Right. So if someone posted on genexp confusion, I would suggest
'write a full generator function'.
| Instead these were _added_ to the language!
As a convenience.
Actually, if one uses more that one for-clause in a generator expression,
there is a potential gotcha in relation to name capture. So if that bites,
the genexp is not so much a convenience, and one might better write
the full function.
tjr
More information about the Python-list
mailing list