subexpressions

A.T.Hofkamp hat at se-126.se.wtb.tue.nl
Fri Jun 1 06:51:18 EDT 2007


On 2007-06-01, Sergey Dorofeev <sergey at fidoman.ru> wrote:
> Hello all!
>
> Please help, is there way to use sub-expressions in lambda?
> For example, if I want to calculate sin(x^2)+cos(x^2) I must code:
> lambda x: sin(x*x)+cos(x*x)
> How to make x*x to be evaluated once?

lambda x: (lambda y: sin(y) + cos(y))(x*x)

Albert




More information about the Python-list mailing list