subexpressions

Kay Schluehr kay.schluehr at gmx.net
Fri Jun 1 13:17:56 EDT 2007


On Jun 1, 9:51 am, "Sergey Dorofeev" <ser... 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=x*x: math.sin(y)+math.cos(y))()

Kay




More information about the Python-list mailing list