[Python-ideas] a new lambda syntax

Ben Finney ben+python at benfinney.id.au
Mon Oct 19 22:50:11 CEST 2009


starwing <weasley_wx at qq.com> writes:

> Oleg Broytman 写道:
> > Single-line lambdas are good enough, and if you need more - just
> > create a named function.

> BUT, why we need a name? just to process something or make decide,
> sometimes code itself is enough.

When the code is more complex than a single expression, it's already
complex enough that defining it first and then referring to it makes for
clearer code.

> and, is there performance problems when you define a inner function in
> another function? (that's, that function will define every time you
> call the function or not?)

Measure the performance difference in your specific code base and decide
on that basis.

If there are such problems, then the lambda form won't help you: it
defines a function of exactly the same type as what ‘def’ defines.

-- 
 \          “I don't like country music, but I don't mean to denigrate |
  `\          those who do. And for the people who like country music, |
_o__)                        denigrate means ‘put down’.” —Bob Newhart |
Ben Finney




More information about the Python-ideas mailing list