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: 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 To: python-list@python.org Subject: Re: Ternary operator associativity In-Reply-To: References: 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 List-Unsubscribe: , List-Archive: List-Post: List-Help: List-Subscribe: , Newsgroups: comp.lang.python Message-ID: 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 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