lambda (and reduce) are valuable

Paul Rubin http
Mon Dec 12 03:51:10 EST 2005


Paul Rubin <http://phr.cx@NOSPAM.invalid> writes:
>     binops = {'+': (lambda x,y: x+y),
>               '-': (lambda x,y: x-y),
>               '*': (lambda x,y: x*y),
>               '/': (lambda x,y: x/y),
>               '**': (lambda x,y: x**y)
>               }
> How would you refactor that, with no lambda?

Ok, with operator.add and so forth.  I don't remember if I knew about
those at the time.  You can easily see though, how additional such
simple functions might be wanted, that aren't in the operator module.



More information about the Python-list mailing list