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
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
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
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.
>
>
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
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
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
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
--- 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
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))
_
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
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
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
[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
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
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
[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
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
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
>>
>>
>>
--- 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
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
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
[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
"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
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
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
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
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
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.
>
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
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
[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
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
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
>> 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
"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
>
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
--- 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
--- 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
--- 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
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)
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
>
>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?
>
>
> 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.
"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
>
> 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
=
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 =
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
>
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
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
--- 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
--- "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 '
"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
> 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
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
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
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
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
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
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
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)
>
--- "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.
--- 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
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
"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
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
"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?
>>>
>>
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)
>
"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
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)
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
71 matches
Mail list logo