AlternateLambdaSyntax - Python Wiki: "AlternateLambdaSyntax"
'via Blog this'
I must admit, I find the Python lambda syntax a bit unpleaasant:
Ordinary function
def foo(x):Lambda
return x+1
lambda x: x+1It is a pity thaat Pythin's lambdaas are not multiline:
http://stackoverflow.com/questions/1233448/no-multiline-lambda-in-python-why-not
This seems to be aa consequence of Python not being indentation sensitive inside parens.
I think that it is also a pity that Python's lambdas are strictly anonymous - although you can assign them a named variable.
I personally often use lambdas not just for anonymous functions, but also for named functions that I want to define near point of use, in the narrowest scope possible.
Even if they could be a lambda, naming them gives nicer stack traces.
No comments:
Post a Comment