LAMBDA IS IT USELESS?
Ralf Muschall
ralf.muschall at alphasat.de
Fri Jul 13 11:31:21 EDT 2001
"EricIDLE" <grayson-wilson at home.com> writes:
> f = reduce(lambda x,y: x*y,n)
> Anyways back to the point the book says this is easier!?!?
It is like using nameless intermediary results.
You might expand your code into
aux = lambda x,y: x*y
f = reduce(aux,n)
and then replace my first line with the equivalent pair of lines
def aux(x,y):
return x*y
The whole thing is similar to writing
f = a*b*c
instead of
aux = a*b
f = aux*c
, just with other types (functions instead of numbers).
Ralf
More information about the Python-list
mailing list