Path: csiph.com!usenet.pasdenom.info!news.franciliens.net!news.muarf.org!news.ecp.fr!feeder1.cambriumusenet.nl!82.197.223.103.MISMATCH!feeder3.cambriumusenet.nl!feed.tweaknews.nl!194.109.133.86.MISMATCH!newsfeed.xs4all.nl!newsfeed3.news.xs4all.nl!xs4all!newsgate.cistron.nl!newsgate.news.xs4all.nl!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.029 X-Spam-Evidence: '*H*': 0.94; '*S*': 0.00; 'lawrence': 0.09; 'messing': 0.09; 'subject:test': 0.09; 'thx': 0.09; 'python': 0.11; 'agree.': 0.16; 'does,': 0.16; 'expression.': 0.16; 'from:addr:torriem': 0.16; 'from:name:michael torrie': 0.16; 'ternary': 0.16; 'wrote:': 0.18; '>>>': 0.22; 'hack': 0.22; 'header:User-Agent:1': 0.23; 'header:In-Reply-To:1': 0.27; 'am,': 0.29; 'bugs': 0.33; 'not.': 0.33; 'could': 0.34; 'but': 0.35; 'really': 0.36; 'message-id:@gmail.com': 0.38; 'to:addr:python- list': 0.38; 'does': 0.39; 'to:addr:python.org': 0.39; 'received:org': 0.40; 'expression': 0.60; 'charset:windows-1252': 0.65; 'believe': 0.68; '2.5.': 0.84; 'idiom': 0.84; 'subject::': 0.85; 'not:': 0.91 X-Virus-Scanned: amavisd-new at torriefamily.org Date: Wed, 22 Oct 2014 11:16:48 -0600 From: Michael Torrie User-Agent: Mozilla/5.0 (X11; Linux x86_64; rv:17.0) Gecko/20131118 Thunderbird/17.0.11 MIME-Version: 1.0 To: python-list@python.org Subject: Re: (test) ? a:b References: <54476af8$0$21651$426a74cc@news.free.fr> <7839376e-fc27-4299-ae63-4ddf17ef9a8a@googlegroups.com> <544775ca$0$2146$426a74cc@news.free.fr> In-Reply-To: Content-Type: text/plain; charset=windows-1252 Content-Transfer-Encoding: 7bit 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: 1413999869 news.xs4all.nl 2838 [2001:888:2000:d::a6]:52341 X-Complaints-To: abuse@xs4all.nl Xref: csiph.com comp.lang.python:79462 On 10/22/2014 05:45 AM, Mark Lawrence wrote: >>> without not: >>> j = [j+1, 3][j>=10] >>> with not: >>> j = [3, j+1][not (j>=10)] >>> >> >> Oh it's a trick ! >> thx > > IMHO it's just dreadful. Why people insist on messing around like this > I really don't know, it just drives me nuts. This actually was the standard idiom used by many python programs before Python 2.5. But I agree. Don't do this anymore! Python has a ternary if expression. Also the ternary if expression does, I believe short-circuit logic, so the non-chosen path is not calculated. This hack does not. Could lead to interesting bugs depending on your assumptions.