Re: attaching names to subexpressions

2012-10-29 Thread Neil Cerutti
On 2012-10-28, Devin Jeanpierre wrote: >>> The 'canonical way' >>> while True: >>> line = complex_expression >>> if not line: >>> break >>> do_something_with(line) >>> >>> avoids this problem, but I was never really convinced about the beauty / >>> readbility of this constr

Re: attaching names to subexpressions

2012-10-28 Thread Chris Angelico
On Sun, Oct 28, 2012 at 6:12 PM, F.R. wrote: > > How about: > > line = True > while line: > > line = function(x, y, z) > do something with(line) > > ? That's going to go through the body of the loop with a false line before breaking out. In some situations that's not a problem, bu

Re: attaching names to subexpressions

2012-10-28 Thread F.R.
On 10/28/2012 06:57 AM, Devin Jeanpierre wrote: line = function(x, y, z) >while line: > do something with(line) > line = function(x, y, z) How about: line = True while line: line = function(x, y, z) do something with(line) ? Frederic -- http://mail.python.org/mail

Re: attaching names to subexpressions

2012-10-28 Thread Steven D'Aprano
On Sun, 28 Oct 2012 01:57:45 -0400, Devin Jeanpierre wrote: > We have a problem, and two solutions. Solution 1 has downside A, and > solution 2 has downside B. If he complains about downside A, you say, > well, use solution 2. If he complains about downside B, you say, well, > use solution 1. > >

Re: attaching names to subexpressions

2012-10-27 Thread Chris Angelico
On Sun, Oct 28, 2012 at 4:57 PM, Devin Jeanpierre wrote: > What if he wants to avoid both downsides A and B? What solution does > he use then? He switches to a language whose BDFL is not Steven D'Aprano. :) No offense meant Steven... ChrisA -- http://mail.python.org/mailman/listinfo/python-lis

Re: attaching names to subexpressions

2012-10-27 Thread rusi
On Oct 28, 5:49 am, Steven D'Aprano wrote: > It's sure as hell more beautiful and readable than assignment as an > expression. > > If we are going to judge code on the ability of people to take a quick > glance and immediately understand it, then pretty much nothing but > trivial one-liners will

Re: attaching names to subexpressions

2012-10-27 Thread Gelonida N
On 10/27/2012 04:42 AM, Steve Howell wrote: > I have been reading the thread "while expression feature proposal," > and one of the interesting outcomes of the thread is the idea that > Python could allow you to attach names to subexpressions, much like C > allows. In C you

attaching names to subexpressions

2012-10-26 Thread Steve Howell
I have been reading the thread "while expression feature proposal," and one of the interesting outcomes of the thread is the idea that Python could allow you to attach names to subexpressions, much like C allows. In C you can say something like this: tax_next_year = (new_salary = s

Re: subexpressions (OT: math)

2007-06-04 Thread Steve Howell
--- Wildemar Wildenburger <[EMAIL PROTECTED]> wrote: > > > Oh my, remember when we used to discuss murderous > snakes and silly > British comedians on this group? > I hardly do ... > /W Although all of us are mere amateurs in this business of making parameters when it's circles in question I

Re: subexpressions (OT: math)

2007-06-04 Thread Steve Howell
ing to bring this back to Python, I think Fourier Series make a better example of a situation where you end up repeating subexpressions: lambda t: a[0]/2 + sum(a[n]*cos(n*f*t) + b[n]*sin(n*f*t) \ for n in range(1,101)) _

Re: subexpressions (OT: math)

2007-06-04 Thread Wildemar Wildenburger
Peter Otten wrote: > [EMAIL PROTECTED] wrote: > > >> sine is a dimensionless value. >> if we expand sine in taylor series sin(x) = x - (x^3)/6 + (x^5)/120 >> etc. >> you can see that sin can be dimensionless only if x is dimensionless >> too. >> > > With y = x^2 = 1/3 pi^2 - 4(cos x - cos(2

Re: subexpressions (OT: math)

2007-06-04 Thread Peter Otten
Wildemar Wildenburger wrote: > Peter Otten wrote: >> With y = x^2 = 1/3 pi^2 - 4(cos x - cos(2x)/2^2 + cos(3x)/3^2 - ...) >> >> area is dimensionless, too, I suppose. >> > > Ehr, ... maybe this is obvious, but I don't see it: Please explain the > second equality sign. I know not much more abo

Re: subexpressions (OT: math)

2007-06-04 Thread Wildemar Wildenburger
Peter Otten wrote: > With y = x^2 = 1/3 pi^2 - 4(cos x - cos(2x)/2^2 + cos(3x)/3^2 - ...) > > area is dimensionless, too, I suppose. > Ehr, ... maybe this is obvious, but I don't see it: Please explain the second equality sign. /W -- http://mail.python.org/mailman/listinfo/python-list

Re: subexpressions (OT: math)

2007-06-04 Thread Peter Otten
[EMAIL PROTECTED] wrote: > sine is a dimensionless value. > if we expand sine in taylor series sin(x) = x - (x^3)/6 + (x^5)/120 > etc. > you can see that sin can be dimensionless only if x is dimensionless > too. With y = x^2 = 1/3 pi^2 - 4(cos x - cos(2x)/2^2 + cos(3x)/3^2 - ...) area is dimens

Re: subexpressions (OT: math)

2007-06-04 Thread Wildemar Wildenburger
Erik Max Francis wrote: > Wildemar Wildenburger wrote: > > >> So in each term of the sum you have a derivative of f, which in the >> case of the sine function translates to sine and cosine functions at the >> point 0. It's not like you're rid of the function just by doing a >> polynomial exp

Re: subexpressions (OT: math)

2007-06-04 Thread Erik Max Francis
Wildemar Wildenburger wrote: > So in each term of the sum you have a derivative of f, which in the > case of the sine function translates to sine and cosine functions at the > point 0. It's not like you're rid of the function just by doing a > polynomial expansion. The only way to *solve* this

Re: subexpressions (OT: math)

2007-06-04 Thread Wildemar Wildenburger
[EMAIL PROTECTED] wrote: > if you are discordant read more :P : > sine is a dimensionless value. > if we expand sine in taylor series sin(x) = x - (x^3)/6 + (x^5)/120 > etc. > you can see that sin can be dimensionless only if x is dimensionless > too. > > I am a professional physicist and a know ab

Re: subexpressions (OT: math)

2007-06-04 Thread stef
Gary Herron wrote: > Wildemar Wildenburger wrote: > >> Gary Herron wrote: >> >> >>> Of course not! Angles have units, commonly either degrees or radians. >>> >>> However, sines and cosines, being ratios of two lengths, are unit-less. >>> >>> >>> To understand it: sin

Re: subexpressions (OT: math)

2007-06-03 Thread Wildemar Wildenburger
Gary Herron wrote: >> The radian is defined as the ratio of an arc of circumfence of a circle >> to the radius of the circle and is therefore *dimensionless*. End of story. >> http://en.wikipedia.org/wiki/Radian and esp. >> http://en.wikipedia.org/wiki/Radian#Dimensional_analysis >> >> >>

Re: subexpressions (OT: math)

2007-06-03 Thread Steve Howell
--- Alex Martelli <[EMAIL PROTECTED]> wrote: > > I blame the > Babylonians for that > confusion just as much as for the clunky base-60 > that intrudes in our > ordinary time reckoning...! > I apologize for helping to start this whole ridiculous thread, although I hope some people have been ente

Re: subexpressions (OT: math)

2007-06-03 Thread Erik Max Francis
Gary Herron wrote: > No, not end-of-story. Neither of us are being precise enough here. To > quote from your second link: > "Although the radian is a unit of measure, it is a dimensionless > quantity." > > But NOTE: Radians and degrees *are* units of measure., however those > units are dime

Re: subexpressions (OT: math)

2007-06-03 Thread Erik Max Francis
Gary Herron wrote: > Of course not! Angles have units, commonly either degrees or radians. ... > I don't know of any name for the units of "sqrt of angle", but that > doesn't invalidate the claim that the value *is* a dimensioned > quantity. In lieu of a name, we'd have to label such a q

Re: subexpressions (OT: math)

2007-06-03 Thread Alex Martelli
[EMAIL PROTECTED] <[EMAIL PROTECTED]> wrote: > On 3, 22:07, "[EMAIL PROTECTED]" <[EMAIL PROTECTED]> wrote: > > > > angle is a ratio of two length and > >dimensionless.http://en.wikipedia.org/wiki/Angle#Units_of_measure_for_ang > >les > > > > only dimensionless values can be a argument of a sin

Re: subexpressions (OT: math)

2007-06-03 Thread Lloyd Zusman
"Steven D'Aprano" <[EMAIL PROTECTED]> writes: > On Sun, 03 Jun 2007 11:26:40 -0700, [EMAIL PROTECTED] wrote: > >> if you are discordant read more :P : >> sine is a dimensionless value. >> if we expand sine in taylor series sin(x) = x - (x^3)/6 + (x^5)/120 >> etc. >> you can see that sin can be dim

Re: subexpressions (OT: math)

2007-06-03 Thread Gary Herron
Wildemar Wildenburger wrote: > Gary Herron wrote: > >> Of course not! Angles have units, commonly either degrees or radians. >> >> However, sines and cosines, being ratios of two lengths, are unit-less. >> >> >>> To understand it: sin() can't have dimensioned argument. It is can't >>> t

Re: subexpressions (OT: math)

2007-06-03 Thread Wildemar Wildenburger
Gary Herron wrote: > Of course not! Angles have units, commonly either degrees or radians. > > However, sines and cosines, being ratios of two lengths, are unit-less. > >> To understand it: sin() can't have dimensioned argument. It is can't >> to be - sin(meters) >> >> > No it's sin(rad

Re: subexpressions (OT: math)

2007-06-03 Thread Steven D'Aprano
On Sun, 03 Jun 2007 11:26:40 -0700, [EMAIL PROTECTED] wrote: > if you are discordant read more :P : > sine is a dimensionless value. > if we expand sine in taylor series sin(x) = x - (x^3)/6 + (x^5)/120 > etc. > you can see that sin can be dimensionless only if x is dimensionless > too. > > I am

Re: subexpressions (OT: math)

2007-06-03 Thread Steve Howell
What's the square root of -1 radians? :) Park yourself in front of a world of choices in alternative vehicles. Visit the Yahoo! Auto Green Center. http://autos.yahoo.com/green_center/ -- http://mail.p

Re: subexpressions (OT: math)

2007-06-03 Thread Cameron Laird
In article <[EMAIL PROTECTED]>, Leonhard Vogt <[EMAIL PROTECTED]> wrote: >>> Yes, I understand that, but what is the geometrical >>> meaning of the square root of an arc length? >> >> That's a different question to your original question, which was asking >> about the square root of an angle. >

Re: subexpressions (OT: math)

2007-06-03 Thread [EMAIL PROTECTED]
On 3, 22:07, "[EMAIL PROTECTED]" <[EMAIL PROTECTED]> wrote: > > angle is a ratio of two length and > dimensionless.http://en.wikipedia.org/wiki/Angle#Units_of_measure_for_angles > > only dimensionless values can be a argument of a sine and exponent! > Are you discordant? if you are discordant

Re: subexpressions (OT: math)

2007-06-03 Thread [EMAIL PROTECTED]
On 3, 21:43, Gary Herron <[EMAIL PROTECTED]> wrote: > [EMAIL PROTECTED] wrote: > > > angle is dimensionless unit. > > Of course not! Angles have units, commonly either degrees or radians. > > However, sines and cosines, being ratios of two lengths, are unit-less.> To > understand it: sin() ca

Re: subexpressions (OT: math)

2007-06-03 Thread Gary Herron
[EMAIL PROTECTED] wrote: > On 3, 14:05, Steven D'Aprano <[EMAIL PROTECTED]> > wrote: > >> On Sun, 03 Jun 2007 09:02:11 +0200, Leonhard Vogt wrote: >> bla-bla >> Hmmm... perhaps that's why the author of the "units" program doesn't >> treat angles as dimensionless when

Re: subexpressions (OT: math)

2007-06-03 Thread [EMAIL PROTECTED]
On 3, 14:05, Steven D'Aprano <[EMAIL PROTECTED]> wrote: > On Sun, 03 Jun 2007 09:02:11 +0200, Leonhard Vogt wrote: > >> bla-bla > > Hmmm... perhaps that's why the author of the "units" program doesn't > treat angles as dimensionless when taking square roots. > > Given that, I withdraw my claim

Re: subexpressions (OT: math)

2007-06-03 Thread Steven D'Aprano
On Sun, 03 Jun 2007 09:02:11 +0200, Leonhard Vogt wrote: >> Angles are a ratio of two lengths, and are therefore dimensionless units. >> So the square root of an angle is just another angle, in the same units, >> and it requires no special geometric interpretation: the square root of 25 >> degree

Re: subexpressions (OT: math)

2007-06-03 Thread Leonhard Vogt
>> Yes, I understand that, but what is the geometrical >> meaning of the square root of an arc length? > > That's a different question to your original question, which was asking > about the square root of an angle. > >> And what would the units be? > > Angles are a ratio of two lengths, and

Re: subexpressions (OT: math)

2007-06-02 Thread Hendrik van Rooyen
"Steve Howell" wrote: > > --- Steven D'Aprano > <[EMAIL PROTECTED]> wrote: > > Angles are real numbers (in the maths sense), so > > sqrt(pi/4) radians is > > just as reasonable an angle as pi/4 radians. Both > > are irrational numbers > > (that is, can't be written exactly as the ratio of >

Re: subexpressions (OT: math)

2007-06-02 Thread Steven D'Aprano
On Sat, 02 Jun 2007 08:29:59 -0700, Steve Howell wrote: > > --- Steven D'Aprano > <[EMAIL PROTECTED]> wrote: > >> On Sat, 02 Jun 2007 05:54:51 -0700, Steve Howell >> wrote: >> >> >> >> >>def f(x): y = x*x; return sin(y)+cos(y); >> >> >> > >> > Although I know valid trigonometry is not th

Re: subexpressions (fourier example)

2007-06-02 Thread Steve Howell
--- Steve Howell <[EMAIL PROTECTED]> wrote: > > --- Stef Mientki <[EMAIL PROTECTED]> > wrote: > > Maybe he meant > >sin(x)^2 + cos(x)^2 > > which is well known demodulation technique if you > > create two signals 90 degrees out of phase. > > > A more realistic subexpression where you migh

Re: subexpressions

2007-06-02 Thread Steve Howell
--- Stef Mientki <[EMAIL PROTECTED]> wrote: > Maybe he meant >sin(x)^2 + cos(x)^2 > which is well known demodulation technique if you > create two signals 90 degrees out of phase. > There's a shorter way to phrase that expression, of course. :) 1

Re: subexpressions (OT: math)

2007-06-02 Thread Steve Howell
--- Steven D'Aprano <[EMAIL PROTECTED]> wrote: > On Sat, 02 Jun 2007 05:54:51 -0700, Steve Howell > wrote: > > >> > >>def f(x): y = x*x; return sin(y)+cos(y); > >> > > > > Although I know valid trigonometry is not the > point of > > this exercise, I'm still trying to figure out why > > an

Re: subexpressions

2007-06-02 Thread Stef Mientki
Steve Howell wrote: >>def f(x): y = x*x; return sin(y)+cos(y); >> > > Although I know valid trigonometry is not the point of > this exercise, I'm still trying to figure out why > anybody would ever take the square of an angle. > What's the square root of pi/4 radians? Maybe he meant sin(x)

Re: subexpressions

2007-06-02 Thread Steven D'Aprano
On Sat, 02 Jun 2007 05:54:51 -0700, Steve Howell wrote: >> >>def f(x): y = x*x; return sin(y)+cos(y); >> > > Although I know valid trigonometry is not the point of > this exercise, I'm still trying to figure out why > anybody would ever take the square of an angle. > What's the square root

Re: subexpressions

2007-06-02 Thread Steve Howell
> >def f(x): y = x*x; return sin(y)+cos(y); > Although I know valid trigonometry is not the point of this exercise, I'm still trying to figure out why anybody would ever take the square of an angle. What's the square root of pi/4 radians?

Re: subexpressions

2007-06-02 Thread Stef Mientki
> > > Check the two alternatives: > > def f(x): > y = x*x > return sin(y) + cos(y) > > 44 key presses, including tabs and newlines and a blank line after the > function, but excluding counting the shift key separately. > > lambda x: (lambda y: sin(y) + cos(y))(x*x) > > 42 key presses.

Re: subexpressions

2007-06-01 Thread Terry Reedy
"Cousin Stanley" <[EMAIL PROTECTED]> wrote in message news:[EMAIL PROTECTED] | | > | > After years of discussion, Guido has decided | > to leave lambda alone for 3.0. | > | > It will not be neither expanded, nor removed, nor renamed. | | But it still will be as ugh, ugh, ugh-lee | as a mul

Re: subexpressions

2007-06-01 Thread Cousin Stanley
> > After years of discussion, Guido has decided > to leave lambda alone for 3.0. > > It will not be neither expanded, nor removed, nor renamed. But it still will be as ugh, ugh, ugh-lee as a mule walking backwards . ;-) -- Stanley C. Kitching Human Being Phoenix, Arizona =

Re: subexpressions

2007-06-01 Thread Steven D'Aprano
On Fri, 01 Jun 2007 07:09:50 -0400, Steve Holden wrote: > 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. >>> def f(x): >>>y =

Re: subexpressions

2007-06-01 Thread Paul Boddie
Steve Howell wrote: > > The compiler doesn't know the types up front, but if > you wanted to do this kind of optimization (and you > believed that 95% of x*x cases would benefit from it, > and you're willing to sacrifice performance for the 5% > of folks that overload multiply), then the compiler >

Re: subexpressions

2007-06-01 Thread Steven Bethard
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) [and later] > This code is needed once in a map, Peter Otten wrote: > Perhaps you like [sin(y)+cos(y) for y in (x

Re: subexpressions

2007-06-01 Thread Kay Schluehr
On Jun 1, 9:51 am, "Sergey Dorofeev" <[EMAIL PROTECTED]> 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

Re: subexpressions

2007-06-01 Thread Steve Howell
--- Paul Boddie <[EMAIL PROTECTED]> wrote: > On 1 Jun, 12:55, Steve Howell <[EMAIL PROTECTED]> > wrote: > > FWIW there's the possibility that even without a > > subexpression syntax, some Python implementations > > would detect the duplication of x*x and optimize > that > > for you. It would hav

Re: subexpressions

2007-06-01 Thread Steve Howell
--- "Diez B. Roggisch" <[EMAIL PROTECTED]> wrote: > The elegance of that solution very much depends on > the cost of the duplicate > operation vs. the additional function call. > > And for the usecase at hand, that's exactly the > point not to do it: > > [EMAIL PROTECTED]:/tmp$ python -m timeit '

Re: subexpressions

2007-06-01 Thread Terry Reedy
"Sergey Dorofeev" <[EMAIL PROTECTED]> wrote in message news:[EMAIL PROTECTED] | How to make x*x to be evaluated once? Addendum to the answers already posted: In Python, lambda params: expression is an inline abbreviation for def (params): return expression except that there is no external bi

Re: subexpressions

2007-06-01 Thread Diez B. Roggisch
> Ok, I stand corrected. > > Duplicate subexpressions are pretty easy to avoid in > Python, so though an optimization would not be > impossible here (checking for immutability of > builtins, etc., which still assumes the idea that > multiplication is more expens

Re: subexpressions

2007-06-01 Thread Steve Howell
o know that x*x had no > side > > effects, which I think is a safe assumption even > in a > > dynamic language like Python. > > No, x may be an object that has the __mul__ special > method, and it may have > side effects. > Ok, I stand corrected. Duplicate su

Re: subexpressions

2007-06-01 Thread Diez B. Roggisch
Steve Howell wrote: > --- Sergey Dorofeev <[EMAIL PROTECTED]> wrote: >> > What syntax would you suggest for a lambda >> enhanced to cover your use >> > case? >> > I suppose you will end up with roughly the same >> number of characters, all >> > crammed in one line -- or broken into lines at a >> r

Re: subexpressions

2007-06-01 Thread Paul Boddie
On 1 Jun, 12:55, Steve Howell <[EMAIL PROTECTED]> wrote: > > FWIW there's the possibility that even without a > subexpression syntax, some Python implementations > would detect the duplication of x*x and optimize that > for you. It would have to know that x*x had no side > effects, which I think i

Re: subexpressions

2007-06-01 Thread Bruno Desthuilliers
Steve Holden a écrit : (snip) > Stop thinking of three lines as "extensive coding" and your problem > disappears immediately. Lol ! +1 QOTW -- http://mail.python.org/mailman/listinfo/python-list

Re: subexpressions

2007-06-01 Thread Tijs
Steve Howell wrote: > FWIW there's the possibility that even without a > subexpression syntax, some Python implementations > would detect the duplication of x*x and optimize that > for you. It would have to know that x*x had no side > effects, which I think is a safe assumption even in a > dynamic

Re: subexpressions

2007-06-01 Thread Steve Holden
Sergey Dorofeev wrote: > "Peter Otten" <[EMAIL PROTECTED]> wrote in message > news:[EMAIL PROTECTED] > 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

Re: subexpressions

2007-06-01 Thread Steve Holden
Sergey Dorofeev wrote: > "Peter Otten" <[EMAIL PROTECTED]> wrote in message > news:[EMAIL PROTECTED] >> 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) >

Re: subexpressions

2007-06-01 Thread Steve Howell
--- "A.T.Hofkamp" <[EMAIL PROTECTED]> wrote: > > lambda x: (lambda y: sin(y) + cos(y))(x*x) > Elegant. I find the use of y confusing there (thinking about the unit circle), so I'd amend it to this: lambda x: (lambda x2: sin(x2) + cos(x2))(x*x) But I like the overall idea.

Re: subexpressions

2007-06-01 Thread Steve Howell
--- Sergey Dorofeev <[EMAIL PROTECTED]> wrote: > > What syntax would you suggest for a lambda > enhanced to cover your use > > case? > > I suppose you will end up with roughly the same > number of characters, all > > crammed in one line -- or broken into lines at a > random position as it > > happ

Re: subexpressions

2007-06-01 Thread A.T.Hofkamp
On 2007-06-01, Sergey Dorofeev <[EMAIL PROTECTED]> 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

Re: subexpressions

2007-06-01 Thread Sergey Dorofeev
"Peter Otten" <[EMAIL PROTECTED]> wrote in message news:[EMAIL PROTECTED] > What syntax would you suggest for a lambda enhanced to cover your use > case? > I suppose you will end up with roughly the same number of characters, all > crammed in one line -- or broken into lines at a random positio

Re: subexpressions

2007-06-01 Thread Peter Otten
Sergey Dorofeev wrote: > > "Peter Otten" <[EMAIL PROTECTED]> wrote in message > news:[EMAIL PROTECTED] > 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

Re: subexpressions

2007-06-01 Thread Sergey Dorofeev
"Peter Otten" <[EMAIL PROTECTED]> wrote in message news:[EMAIL PROTECTED] 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? >>> >>

Re: subexpressions

2007-06-01 Thread Peter Otten
Sergey Dorofeev wrote: > "Peter Otten" <[EMAIL PROTECTED]> wrote in message > news:[EMAIL PROTECTED] >> 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) >

Re: subexpressions

2007-06-01 Thread Sergey Dorofeev
"Peter Otten" <[EMAIL PROTECTED]> wrote in message news:[EMAIL PROTECTED] > 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 evaluat

Re: subexpressions

2007-06-01 Thread Peter Otten
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]][0])(.5) == sin(.5*.5)

subexpressions

2007-06-01 Thread Sergey Dorofeev
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? -- http://mail.python.org/mailman/listinfo/python-list