On 30 March 2010 18:40, gentlestone tibor.b...@hotmail.com wrote:
Hi, how can I write the popular C/JAVA syntax in Python?
Java example:
return (a==b) ? 'Yes' : 'No'
My first idea is:
return ('No','Yes')[bool(a==b)]
Is there a more elegant/common python expression for this?
I'm
On Sun, 11 Apr 2010 21:35:49 -0700, Aahz wrote:
In article mailman.1330.1269981186.23598.python-l...@python.org, Steve
Holden st...@holdenweb.com wrote:
It exists because people nagged Guido mercilessly until, against his
better judgment, he capitulated.
No, the ternary exists because he
In article mailman.1330.1269981186.23598.python-l...@python.org,
Steve Holden st...@holdenweb.com wrote:
It exists because people nagged Guido mercilessly until, against his
better judgment, he capitulated.
No, the ternary exists because he became convinced that it was the
lesser evil compared
Steven D'Aprano ste...@remove.this.cybersource.com.au wrote:
On Tue, 06 Apr 2010 16:54:18 +, Duncan Booth wrote:
Albert van der Horst alb...@spenarnc.xs4all.nl wrote:
Old hands would have ...
stamp =( weight=1000 and 120 or
weight=500 and 100 or
On 4/6/2010 9:20 PM Steven D'Aprano said...
On Tue, 06 Apr 2010 16:54:18 +, Duncan Booth wrote:
Most old hands would (IMHO) write the if statements out in full,
though some might remember that Python comes 'batteries included':
from bisect import bisect
WEIGHTS = [100, 250, 500, 1000]
In article houv8a$ed9$0...@news.t-online.com,
Peter Otten __pete...@web.de wrote:
Pierre Quentel wrote:
I'm surprised nobody proposed a solution with itertools ;-)
next(itertools.takewhile(lambda _: a == b, [yes]), no)
I could learn something here, if you explain it?
You spoke to soon
, gentlestone tibor.b...@hotmail.com
wrote:
Hi, how can I write the popular C/JAVA syntax in Python?
Java example:
return (a==b) ? 'Yes' : 'No'
My first idea is:
return ('No','Yes')[bool(a==b)]
Is there a more elegant/common python expression for this?
Yes, Python has ternary operator-like
On 04/07/10 00:16, Albert van der Horst wrote:
In article houv8a$ed9$0...@news.t-online.com,
Peter Otten __pete...@web.de wrote:
Pierre Quentel wrote:
I'm surprised nobody proposed a solution with itertools ;-)
next(itertools.takewhile(lambda _: a == b, [yes]), no)
I could learn
Albert van der Horst alb...@spenarnc.xs4all.nl wrote:
Old hands would have ...
stamp =( weight=1000 and 120 or
weight=500 and 100 or
weight=250 and 80 or
weight=100 and 60 or
44 )
(Kind of a brain
On Tue, 06 Apr 2010 16:54:18 +, Duncan Booth wrote:
Albert van der Horst alb...@spenarnc.xs4all.nl wrote:
Old hands would have ...
stamp =( weight=1000 and 120 or
weight=500 and 100 or
weight=250 and 80 or
weight=100 and 60 or
Steven D'Aprano wrote:
Not according to the PEP. No fewer than 16 alternatives were put to a
vote, and with no clear winner (but many obvious losers) Guido made the
final decision.
As I remember, the decision made on the basis of the vote
was *not* to add a conditional expression at all,
On Mon, 05 Apr 2010 12:08:31 +1200, Gregory Ewing wrote:
Steven D'Aprano wrote:
Not according to the PEP. No fewer than 16 alternatives were put to a
vote, and with no clear winner (but many obvious losers) Guido made the
final decision.
As I remember, the decision made on the basis of
Steve Howell showel...@yahoo.com writes:
In languages like Ruby/Perl the inverted if statement is also a useful
idiom to emphasize concisely that code is exceptional in nature:
def quotient(m, n)
# guard code
return None if n == 0
# happy path
return m / n
end
Still, in Perl I
In message mailman.1345.1269992641.23598.python-l...@python.org, Steve
Holden wrote:
Lawrence D'Oliveiro wrote:
By the way, you don’t need the parentheses.
But at the same time, if you don't *absolutely know* you don't need the
parentheses ...
But you can “abolutely know”—it’s all
On Sun, 04 Apr 2010 12:26:05 +1200, Lawrence D'Oliveiro wrote:
In message mailman.1345.1269992641.23598.python-l...@python.org, Steve
Holden wrote:
Lawrence D'Oliveiro wrote:
By the way, you don’t need the parentheses.
But at the same time, if you don't *absolutely know* you don't need
On Thu, 01 Apr 2010 21:16:18 -0700, Steve Howell wrote:
The ironic thing about the ternary operator is that it is not really
ternary; it's binary. Even just making an expression from a binary
operator inevitably leads to syntax hell.
There is a principle of programming that I would like to
Steven D'Aprano st...@remove-this-cybersource.com.au wrote:
Yes, I agree, we should be using the previously well known syntax:
condition - value_if_true, value_if_false
which was introduced by BCPL in 1966.
What, not this?
VALOF TEST condition THEN RESULTIS value_if_true ELSE RESULTIS
On Apr 2, 2:04 am, Steven D'Aprano st...@remove-this-
cybersource.com.au wrote:
On Thu, 01 Apr 2010 21:16:18 -0700, Steve Howell wrote:
The ironic thing about the ternary operator is that it is not really
ternary; it's binary. Even just making an expression from a binary
operator
Steve Howell wrote:
On Apr 2, 2:04 am, Steven D'Aprano st...@remove-this-
cybersource.com.au wrote:
[...]
How is the ternary operator not really ternary, it's binary? It
requires three arguments, not two, which makes it ternary. In Python
syntax:
Of course, I understand that the ternary
On Apr 2, 7:05 am, Steve Howell showel...@yahoo.com wrote:
On Apr 2, 2:04 am, Steven D'Aprano st...@remove-this-
cybersource.com.au wrote:
On Thu, 01 Apr 2010 21:16:18 -0700, Steve Howell wrote:
The ironic thing about the ternary operator is that it is not really
ternary; it's binary.
On Apr 2, 7:21 am, Steve Holden st...@holdenweb.com wrote:
Steve Howell wrote:
On Apr 2, 2:04 am, Steven D'Aprano st...@remove-this-
cybersource.com.au wrote:
[...]
How is the ternary operator not really ternary, it's binary? It
requires three arguments, not two, which makes it ternary.
Steve Howell wrote:
I forgot this one:
def obfuscated_triager(rolls, pins,
lookup = ['normal'] * 10 + ['strike'] + [None] * 9 + ['spare']
):
return lookup[rolls * pins]
Bah...no need to be _quite_ so obscure:
def triager(rolls, pins):
return {
(1, 10):'strike',
On Apr 2, 7:52 am, Tim Chase python.l...@tim.thechases.com wrote:
Steve Howell wrote:
I forgot this one:
def obfuscated_triager(rolls, pins,
lookup = ['normal'] * 10 + ['strike'] + [None] * 9 + ['spare']
):
return lookup[rolls * pins]
Bah...no need to be _quite_
On Fri, 02 Apr 2010 07:05:49 -0700, Steve Howell wrote:
How is the ternary operator not really ternary, it's binary? It
requires three arguments, not two, which makes it ternary. In Python
syntax:
Of course, I understand that the ternary operator has three arguments,
but it only has two
:
return (a==b) ? 'Yes' : 'No'
My first idea is:
return ('No','Yes')[bool(a==b)]
Is there a more elegant/common python expression for this?
Yes, Python has ternary operator-like syntax:
return ('Yes' if a==b else 'No')
Note that this requires a recent version of Python.
Who let the dogs
kj no.em...@please.post writes:
Anyway, I don't know of any other language that puts the test
between the alternatives. No doubt there's one out there, with
emphasis on out there...
Perl has something that has IMO somewhat the same problem:
print Hello, world!\n if $some_condition;
I
example:
return (a==b) ? 'Yes' : 'No'
My first idea is:
return ('No','Yes')[bool(a==b)]
Is there a more elegant/common python expression for this?
Yes, Python has ternary operator-like syntax:
return ('Yes' if a==b else 'No')
Note that this requires a recent version of Python.
Who
:
return (a==b) ? 'Yes' : 'No'
My first idea is:
return ('No','Yes')[bool(a==b)]
Is there a more elegant/common python expression for this?
Yes, Python has ternary operator-like syntax:
return ('Yes' if a==b else 'No')
Note that this requires a recent version of Python.
Who let
On Apr 2, 3:12 pm, kj no.em...@please.post wrote:
Is that for real??? It's the QWERTY rationale all over again. Swell.
Well, bearing in mind that everybody seems to have an agenda, so you
can't (or shouldn't, anyway) take all your news from a single source,
it may be that the common wisdom
On Fri, 02 Apr 2010 20:12:59 +, kj wrote:
In mailman.1326.1269971785.23598.python-l...@python.org Steve Holden
st...@holdenweb.com writes:
[...]
Yes, that's deliberately awful syntax. Guido designed it that way to
ensure that people didn't aver-use it, thereby reducing the readability
of
On Apr 2, 5:53 pm, Steven D'Aprano st...@remove-this-
cybersource.com.au wrote:
As I've pointed out before, it is natural syntax in English. Not
necessarily the most common, but common enough to be completely
unexceptional:
I'll be there in ten minutes, if I can find a parking space close
On Mar 30, 10:56 am, Steve Holden st...@holdenweb.com wrote:
John Nagle wrote:
Chris Rebert wrote:
On Tue, Mar 30, 2010 at 8:40 AM, gentlestone tibor.b...@hotmail.com
wrote:
Hi, how can I write the popular C/JAVA syntax in Python?
Java example:
return (a==b) ? 'Yes' : 'No'
My
Den wrote:
[...]
I've been following this thread for a few days now. My thoughts are
that, in view of a long known widely used syntax for this operator,
python's syntax seems like change for change sake. If current
programing paradigm provides that particular trinary operator, why
should
On Thu, 01 Apr 2010 08:27:53 -0700, Den wrote about Python's ternary
operator:
I've been following this thread for a few days now. My thoughts are
that, in view of a long known widely used syntax for this operator,
python's syntax seems like change for change sake. If current
programing
On Mar 30, 8:40 am, gentlestone tibor.b...@hotmail.com wrote:
Hi, how can I write the popular C/JAVA syntax in Python?
Java example:
return (a==b) ? 'Yes' : 'No'
; first idea is:
return ('No','Yes')[bool(a==b)]
Is there a more elegant/common python expression
Pierre Quentel wrote:
I'm surprised nobody proposed a solution with itertools ;-)
next(itertools.takewhile(lambda _: a == b, [yes]), no)
You spoke to soon :)
Peter
--
http://mail.python.org/mailman/listinfo/python-list
On 2010-03-31 00:57:51 -0700, Peter Otten __pete...@web.de said:
Pierre Quentel wrote:
I'm surprised nobody proposed a solution with itertools ;-)
next(itertools.takewhile(lambda _: a == b, [yes]), no)
You spoke to soon :)
I salute you, sir, for upholding the standards of this group
found interesting how
symmetrical it was with the one the OP was refering:
(a==b) ? 'Yes' : 'No'
(a==b) and 'Yes' or 'No'
I know, I could write it without parenthesis but it seems more
naturally organized with it and I read it faster and clearly. I dont
know exactly why but it seems also
Hi, how can I write the popular C/JAVA syntax in Python?
Java example:
return (a==b) ? 'Yes' : 'No'
My first idea is:
return ('No','Yes')[bool(a==b)]
Is there a more elegant/common python expression for this?
--
http://mail.python.org/mailman/listinfo/python-list
On Mar 30, 11:40 am, gentlestone tibor.b...@hotmail.com wrote:
Hi, how can I write the popular C/JAVA syntax in Python?
Java example:
return (a==b) ? 'Yes' : 'No'
My first idea is:
return ('No','Yes')[bool(a==b)]
Is there a more elegant/common python expression for this?
return
On Tue, Mar 30, 2010 at 8:40 AM, gentlestone tibor.b...@hotmail.com wrote:
Hi, how can I write the popular C/JAVA syntax in Python?
Java example:
return (a==b) ? 'Yes' : 'No'
My first idea is:
return ('No','Yes')[bool(a==b)]
Is there a more elegant/common python expression
Hi, how can I write the popular C/JAVA syntax in Python?
Java example:
return (a==b) ? 'Yes' : 'No'
My first idea is:
return ('No','Yes')[bool(a==b)]
Is there a more elegant/common python expression for this?
return ('Yes' if a == b else 'No')
And for less clutter you can even
Chris Rebert wrote:
On Tue, Mar 30, 2010 at 8:40 AM, gentlestone tibor.b...@hotmail.com wrote:
Hi, how can I write the popular C/JAVA syntax in Python?
Java example:
return (a==b) ? 'Yes' : 'No'
My first idea is:
return ('No','Yes')[bool(a==b)]
Is there a more elegant/common python
On 2010-03-30 12:08 PM, John Nagle wrote:
Chris Rebert wrote:
On Tue, Mar 30, 2010 at 8:40 AM, gentlestone tibor.b...@hotmail.com
wrote:
Hi, how can I write the popular C/JAVA syntax in Python?
Java example:
return (a==b) ? 'Yes' : 'No'
My first idea is:
return ('No','Yes')[bool(a==b
On Mar 30, 5:40 pm, gentlestone tibor.b...@hotmail.com wrote:
Hi, how can I write the popular C/JAVA syntax in Python?
Java example:
return (a==b) ? 'Yes' : 'No'
My first idea is:
return ('No','Yes')[bool(a==b)]
Is there a more elegant/common python expression for this?
(a==b
On Tue, 30 Mar 2010 08:40:56 -0700, gentlestone wrote:
Hi, how can I write the popular C/JAVA syntax in Python?
Java example:
return (a==b) ? 'Yes' : 'No'
My first idea is:
return ('No','Yes')[bool(a==b)]
You don't need the call to bool.
('No','Yes')[a==b]
Is there a more
On Tue, Mar 30, 2010 at 1:08 PM, John Nagle na...@animats.com wrote:
Chris Rebert wrote:
On Tue, Mar 30, 2010 at 8:40 AM, gentlestone tibor.b...@hotmail.com
wrote:
Hi, how can I write the popular C/JAVA syntax in Python?
Java example:
return (a==b) ? 'Yes' : 'No'
My first idea
On Tue, 30 Mar 2010 10:08:31 -0700, John Nagle wrote:
Yes, Python has ternary operator-like syntax: return ('Yes' if a==b
else 'No')
Note that this requires a recent version of Python.
Who let the dogs in? That's awful syntax.
I used to think so to, but now I like it. It matches
John Nagle wrote:
Chris Rebert wrote:
On Tue, Mar 30, 2010 at 8:40 AM, gentlestone tibor.b...@hotmail.com
wrote:
Hi, how can I write the popular C/JAVA syntax in Python?
Java example:
return (a==b) ? 'Yes' : 'No'
My first idea is:
return ('No','Yes')[bool(a==b)]
Is there a more
On 2010-03-30 12:11 PM, Steven D'Aprano wrote:
On Tue, 30 Mar 2010 10:08:31 -0700, John Nagle wrote:
Yes, Python has ternary operator-like syntax: return ('Yes' if a==b
else 'No')
Note that this requires a recent version of Python.
Who let the dogs in? That's awful syntax.
I used
And thus spake Steve Holden st...@holdenweb.com
Tue, 30 Mar 2010 13:56:04 -0400:
Yes, Python has ternary operator-like syntax:
return ('Yes' if a==b else 'No')
Note that this requires a recent version of Python.
Who let the dogs in? That's awful syntax.
Yes, that's
Robert Fendt no.s...@local.local writes:
In fact, the syntax just shouts 'do [...] unless' to me. And
that's so strong a Perl-ism I cannot quite express how ugly I
actually find it...
And
a == b and 'Yes' or 'No'
isn't a Perl-ism?
Sheesh, this group would be so much nicer without the
On 30 mar, 21:19, John Bokma j...@castleamber.com wrote:
Robert Fendt no.s...@local.local writes:
In fact, the syntax just shouts 'do [...] unless' to me. And
that's so strong a Perl-ism I cannot quite express how ugly I
actually find it...
And
a == b and 'Yes' or 'No'
isn't a
And thus spake John Bokma j...@castleamber.com
Tue, 30 Mar 2010 13:19:19 -0600:
And
a == b and 'Yes' or 'No'
isn't a Perl-ism?
I never said that this would be better. I don't even get the
point of what the advantage is supposed to be of inverting the
order of the return statement and
Robert Fendt wrote:
And thus spake John Bokma j...@castleamber.com
Tue, 30 Mar 2010 13:19:19 -0600:
And
a == b and 'Yes' or 'No'
isn't a Perl-ism?
I never said that this would be better. I don't even get the
point of what the advantage is supposed to be of inverting the
order of
Robert Fendt wrote:
And thus spake John Bokma j...@castleamber.com
Tue, 30 Mar 2010 13:19:19 -0600:
And
a == b and 'Yes' or 'No'
isn't a Perl-ism?
I never said that this would be better. I don't even get the
point of what the advantage is supposed to be of inverting the
order of the
And thus spake MRAB pyt...@mrabarnett.plus.com
Tue, 30 Mar 2010 22:43:04 +0100:
I think you mean that it's very _un-Pythonic_ (perhaps because it's very
very Pythonesque)! :-)
Yes. Of course. What was I thinking. ;-)
Regards,
Robert
--
http://mail.python.org/mailman/listinfo/python-list
On 2010-03-30 13:16:00 -0700, Robert Fendt said:
I find such a convoluted construct especially ugly in a language
which I previously regarded as having a rather striking beauty
of syntactical simplicity. The construct is superfluous,
illogical, unelegant, and thus very un-pythonesque, IMHO. But
In message 7316f3d2-bcc9-4a1a-8598-
cdd5d41fd...@k17g2000yqb.googlegroups.com, Joaquin Abian wrote:
(a==b) and 'YES' or 'NO'
Yes, ugly
Why would you say that’s ugly?
By the way, you don’t need the parentheses.
--
http://mail.python.org/mailman/listinfo/python-list
Lawrence D'Oliveiro wrote:
In message 7316f3d2-bcc9-4a1a-8598-
cdd5d41fd...@k17g2000yqb.googlegroups.com, Joaquin Abian wrote:
(a==b) and 'YES' or 'NO'
Yes, ugly
Why would you say that’s ugly?
By the way, you don’t need the parentheses.
But at the same time, if you don't *absolutely
Robert Fendt no.s...@local.local writes:
And thus spake John Bokma j...@castleamber.com
Tue, 30 Mar 2010 13:19:19 -0600:
And
a == b and 'Yes' or 'No'
isn't a Perl-ism?
I never said that this would be better.
It was not my intention to imply you did. But yet I do see books on
Python
On Mar 30, 10:08 am, John Nagle na...@animats.com wrote:
Chris Rebert wrote:
On Tue, Mar 30, 2010 at 8:40 AM, gentlestone tibor.b...@hotmail.com wrote:
Hi, how can I write the popular C/JAVA syntax in Python?
Java example:
return (a==b) ? 'Yes' : 'No'
My first idea is:
return
John Bokma wrote:
And maybe you're right, the Python one could've been written:
if list is None:
list = []
which looks, now, also more readable to me as well.
Though there's a slight difference[1], I'd usually use
lst = lst or []
for your particular initialization use case.
-tkc
63 matches
Mail list logo