LAMBDA IS IT USELESS?
Greg Ewing
greg at cosc.canterbury.ac.nz
Thu Jul 12 02:00:17 EDT 2001
EricIDLE wrote:
>
> def mult(x,y):
> return x * y
> f = reduce(lambda x,y: x*y,n)
I don't know what the mult function is there for,
since you're not using it in that example. All you
need is
f = reduce(lambda x,y: x*y,n)
> def mult(x,y):
> return x * y
> f = reduce(mult,n)
>
> Isnt that easier??
It's a matter of taste. Some people like the ability
to write very trivial functions like your mult() in-line.
Others find it clearer to define them separately.
If you like the separate version better, feel free
to use it.
--
Greg Ewing, Computer Science Dept, University of Canterbury,
Christchurch, New Zealand
To get my email address, please visit my web page:
http://www.cosc.canterbury.ac.nz/~greg
More information about the Python-list
mailing list