Theoretical question about Lambda
Alex Martelli
aleax at aleax.it
Thu May 2 05:03:44 EDT 2002
pekka niiranen wrote:
> After reading about Scheme, I begun to wonder:
>
> Is there any forced need for Lambda's in Python ? I mean does Lambda
> contribute anything that cannot be done otherwise in Python ?
Not really. lambda lets you have an anonymous function, and create
a function within an expression (while def is a statement and does
require a name), so you may be able to collapse a few things a little
bit more, in theory, e.g.:
funs = [lambda x: x+1, lambda x: x*2]
vs:
def plus1(x): return x+1
def times2(x): return x*2
funs = [plus1, times2]
but that's about it.
Alex
More information about the Python-list
mailing list