sergey at fidoman.ru
Fri Jun 1 10:53:26 CEST 2007
"Peter Otten" <__peter__ at web.de> wrote in message
news:f3ok60$vp7$03$1 at news.t-online.com...
> Sergey Dorofeev wrote:
>> 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: [sin(x2) + cos(x2) for x2 in [x*x]])(.5) == sin(.5*.5) +
> The real answer is of course: Use a function.
But what about something like
lambda x: sin(y)+cos(y) where y=x*x
May be this could be a PEP? If there is no straight way to do this.
More information about the Python-list