Re: (a==b) ? 'Yes' : 'No'

2010-04-19 Thread Dotan Cohen
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

Re: (a==b) ? 'Yes' : 'No'

2010-04-12 Thread Steven D'Aprano
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

Re: (a==b) ? 'Yes' : 'No'

2010-04-11 Thread Aahz
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

Re: (a==b) ? 'Yes' : 'No'

2010-04-07 Thread Duncan Booth
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

Re: (a==b) ? 'Yes' : 'No'

2010-04-07 Thread Emile van Sebille
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]

Re: (a==b) ? 'Yes' : 'No'

2010-04-06 Thread Albert van der Horst
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

Re: (a==b) ? 'Yes' : 'No'

2010-04-06 Thread Albert van der Horst
, 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

Re: (a==b) ? 'Yes' : 'No'

2010-04-06 Thread Lie Ryan
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

Re: (a==b) ? 'Yes' : 'No'

2010-04-06 Thread Duncan Booth
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

Re: (a==b) ? 'Yes' : 'No'

2010-04-06 Thread Steven D'Aprano
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

Re: (a==b) ? 'Yes' : 'No'

2010-04-04 Thread Gregory Ewing
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,

Re: (a==b) ? 'Yes' : 'No'

2010-04-04 Thread Steven D'Aprano
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

Re: (a==b) ? 'Yes' : 'No'

2010-04-03 Thread John Bokma
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

Re: (a==b) ? 'Yes' : 'No'

2010-04-03 Thread Lawrence D'Oliveiro
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

Re: (a==b) ? 'Yes' : 'No'

2010-04-03 Thread Steven D'Aprano
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

Re: (a==b) ? 'Yes' : 'No'

2010-04-02 Thread Steven D'Aprano
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

Re: (a==b) ? 'Yes' : 'No'

2010-04-02 Thread Duncan Booth
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

Re: (a==b) ? 'Yes' : 'No'

2010-04-02 Thread Steve Howell
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

Re: (a==b) ? 'Yes' : 'No'

2010-04-02 Thread Steve Holden
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

Re: (a==b) ? 'Yes' : 'No'

2010-04-02 Thread Steve Howell
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.

Re: (a==b) ? 'Yes' : 'No'

2010-04-02 Thread Steve Howell
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.

Re: (a==b) ? 'Yes' : 'No'

2010-04-02 Thread Tim Chase
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',

Re: (a==b) ? 'Yes' : 'No'

2010-04-02 Thread Steve Howell
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_

Re: (a==b) ? 'Yes' : 'No'

2010-04-02 Thread Steven D'Aprano
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

Re: (a==b) ? 'Yes' : 'No'

2010-04-02 Thread kj
: 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

Re: (a==b) ? 'Yes' : 'No'

2010-04-02 Thread John Bokma
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

Re: (a==b) ? 'Yes' : 'No'

2010-04-02 Thread Steve Holden
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

Re: (a==b) ? 'Yes' : 'No'

2010-04-02 Thread Ethan Furman
: 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

Re: (a==b) ? 'Yes' : 'No'

2010-04-02 Thread Patrick Maupin
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

Re: (a==b) ? 'Yes' : 'No'

2010-04-02 Thread Steven D'Aprano
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

Re: (a==b) ? 'Yes' : 'No'

2010-04-02 Thread Steve Howell
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

Re: (a==b) ? 'Yes' : 'No'

2010-04-01 Thread Den
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

Re: (a==b) ? 'Yes' : 'No'

2010-04-01 Thread Steve Holden
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

Re: (a==b) ? 'Yes' : 'No'

2010-04-01 Thread Steven D'Aprano
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

Re: (a==b) ? 'Yes' : 'No'

2010-04-01 Thread Steve Howell
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

Re: (a==b) ? 'Yes' : 'No'

2010-03-31 Thread Peter Otten
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

Re: (a==b) ? 'Yes' : 'No'

2010-03-31 Thread TomF
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

Re: (a==b) ? 'Yes' : 'No'

2010-03-31 Thread Joaquin Abian
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

(a==b) ? 'Yes' : 'No'

2010-03-30 Thread gentlestone
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

Re: (a==b) ? 'Yes' : 'No'

2010-03-30 Thread Mike Kent
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

Re: (a==b) ? 'Yes' : 'No'

2010-03-30 Thread Chris Rebert
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

Re: (a==b) ? 'Yes' : 'No'

2010-03-30 Thread Daniel Fetchinson
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

Re: (a==b) ? 'Yes' : 'No'

2010-03-30 Thread John Nagle
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

Re: (a==b) ? 'Yes' : 'No'

2010-03-30 Thread Robert Kern
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

Re: (a==b) ? 'Yes' : 'No'

2010-03-30 Thread Joaquin Abian
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

Re: (a==b) ? 'Yes' : 'No'

2010-03-30 Thread Steven D'Aprano
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

Re: (a==b) ? 'Yes' : 'No'

2010-03-30 Thread Chris Colbert
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

Re: (a==b) ? 'Yes' : 'No'

2010-03-30 Thread Steven D'Aprano
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

Re: (a==b) ? 'Yes' : 'No'

2010-03-30 Thread Steve Holden
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

Re: (a==b) ? 'Yes' : 'No'

2010-03-30 Thread Robert Kern
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

Re: (a==b) ? 'Yes' : 'No'

2010-03-30 Thread Robert Fendt
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

Re: (a==b) ? 'Yes' : 'No'

2010-03-30 Thread John Bokma
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

Re: (a==b) ? 'Yes' : 'No'

2010-03-30 Thread Pierre Quentel
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

Re: (a==b) ? 'Yes' : 'No'

2010-03-30 Thread Robert Fendt
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

Re: (a==b) ? 'Yes' : 'No'

2010-03-30 Thread Steve Holden
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

Re: (a==b) ? 'Yes' : 'No'

2010-03-30 Thread MRAB
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

Re: (a==b) ? 'Yes' : 'No'

2010-03-30 Thread Robert Fendt
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

Re: (a==b) ? 'Yes' : 'No'

2010-03-30 Thread Stephen Hansen
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

Re: (a==b) ? 'Yes' : 'No'

2010-03-30 Thread Lawrence D'Oliveiro
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

Re: (a==b) ? 'Yes' : 'No'

2010-03-30 Thread Steve Holden
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

Re: (a==b) ? 'Yes' : 'No'

2010-03-30 Thread John Bokma
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

Re: (a==b) ? 'Yes' : 'No'

2010-03-30 Thread Russ P.
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

Re: (a==b) ? 'Yes' : 'No'

2010-03-30 Thread Tim Chase
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