Groups | Search | Server Info | Keyboard shortcuts | Login | Register [http] [https] [nntp] [nntps]


Groups > comp.lang.python > #67948

Re: Ternary operator associativity

Path csiph.com!v102.xanadu-bbs.net!xanadu-bbs.net!feeder.erje.net!eu.feeder.erje.net!news.stack.nl!newsfeed.xs4all.nl!newsfeed3a.news.xs4all.nl!xs4all!post.news.xs4all.nl!not-for-mail
Return-Path <python.list@tim.thechases.com>
X-Original-To python-list@python.org
Delivered-To python-list@mail.python.org
X-Spam-Status OK 0.002
X-Spam-Evidence '*H*': 1.00; '*S*': 0.00; 'operator': 0.03; 'advocate': 0.07; 'explicit': 0.07; 'expressions': 0.07; 'mess': 0.09; 'subject:skip:a 10': 0.09; 'suggest': 0.14; '-tkc': 0.16; 'conditional': 0.16; 'from:addr:python.list': 0.16; 'from:addr:tim.thechases.com': 0.16; 'from:name:tim chase': 0.16; 'refactoring': 0.16; 'ternary': 0.16; 'language': 0.16; 'wrote:': 0.18; '>>>': 0.22; 'regardless': 0.24; 'header:In-Reply-To:1': 0.27; 'strongly': 0.30; "i'd": 0.34; 'could': 0.34; 'created': 0.35; 'charset:us-ascii': 0.36; 'to:addr:python-list': 0.38; 'ability': 0.39; 'to:addr:python.org': 0.39; 'according': 0.40; 'first': 0.61; 'making': 0.63; 'such': 0.63; 'more': 0.64; 'received:50.22': 0.84
Date Thu, 6 Mar 2014 12:59:58 -0600
From Tim Chase <python.list@tim.thechases.com>
To python-list@python.org
Subject Re: Ternary operator associativity
In-Reply-To <f3bd8da6-dc2e-4b05-b50b-3a2c9d825367@googlegroups.com>
References <f3bd8da6-dc2e-4b05-b50b-3a2c9d825367@googlegroups.com>
X-Mailer Claws Mail 3.8.1 (GTK+ 2.24.10; x86_64-pc-linux-gnu)
Mime-Version 1.0
Content-Type text/plain; charset=US-ASCII
Content-Transfer-Encoding 7bit
X-AntiAbuse This header was added to track abuse, please include it with any abuse report
X-AntiAbuse Primary Hostname - boston.accountservergroup.com
X-AntiAbuse Original Domain - python.org
X-AntiAbuse Originator/Caller UID/GID - [47 12] / [47 12]
X-AntiAbuse Sender Address Domain - tim.thechases.com
X-Get-Message-Sender-Via boston.accountservergroup.com: authenticated_id: tim@thechases.com
X-BeenThere python-list@python.org
X-Mailman-Version 2.1.15
Precedence list
List-Id General discussion list for the Python programming language <python-list.python.org>
List-Unsubscribe <https://mail.python.org/mailman/options/python-list>, <mailto:python-list-request@python.org?subject=unsubscribe>
List-Archive <http://mail.python.org/pipermail/python-list/>
List-Post <mailto:python-list@python.org>
List-Help <mailto:python-list-request@python.org?subject=help>
List-Subscribe <https://mail.python.org/mailman/listinfo/python-list>, <mailto:python-list-request@python.org?subject=subscribe>
Newsgroups comp.lang.python
Message-ID <mailman.7872.1394132381.18130.python-list@python.org> (permalink)
Lines 19
NNTP-Posting-Host 2001:888:2000:d::a6
X-Trace 1394132381 news.xs4all.nl 2914 [2001:888:2000:d::a6]:54546
X-Complaints-To abuse@xs4all.nl
Xref csiph.com comp.lang.python:67948

Show key headers only | View raw


On 2014-03-06 03:34, candide wrote:
> According to the official documentation, the ternary operator has
> left-to-right associativity 
>
> >>> left_to_right = (0 if 1 else 0) if 0 else 1
> >>> right_to_left = 0 if 1 else (0 if 0 else 1)

I'd never want to rely on my own ability to remember the language
spec, so I strongly advocate for making it explicit with parens
regardless of what the language defines.  And that's if I ever created
such a mess in the first place.  If you have more than one pair of
conditional expressions in a single assignment, I'd suggest that it's
a code-smell that could use refactoring for clarity/disambiguity.

-tkc



Back to comp.lang.python | Previous | NextPrevious in thread | Next in thread | Find similar | Unroll thread


Thread

Ternary operator associativity candide <c.candide@laposte.net> - 2014-03-06 03:34 -0800
  Re: Ternary operator associativity Michael Torrie <torriem@gmail.com> - 2014-03-06 10:47 -0700
  Re: Ternary operator associativity Terry Reedy <tjreedy@udel.edu> - 2014-03-06 13:52 -0500
  Re: Ternary operator associativity Tim Chase <python.list@tim.thechases.com> - 2014-03-06 12:59 -0600
  Re: Ternary operator associativity Terry Reedy <tjreedy@udel.edu> - 2014-03-06 15:15 -0500

csiph-web