Path: csiph.com!usenet.pasdenom.info!news.etla.org!news.stack.nl!newsfeed.xs4all.nl!newsfeed3a.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.001 X-Spam-Evidence: '*H*': 1.00; '*S*': 0.00; 'true,': 0.05; 'indices': 0.07; 'paths': 0.07; 'polish': 0.09; 'received:80.91': 0.09; 'received:80.91.229': 0.09; 'received:gmane.org': 0.09; 'received:list': 0.09; 'subject:test': 0.09; 'python': 0.11; '"end"': 0.16; '"if"': 0.16; '"standard': 0.16; 'boolean': 0.16; 'dictionary).': 0.16; 'evaluates': 0.16; 'evaluating': 0.16; 'evaluation;': 0.16; 'false)': 0.16; 'lambda': 0.16; 'merely': 0.16; 'message-id:@4ax.com': 0.16; 'received:80.91.229.3': 0.16; 'received:plane.gmane.org': 0.16; 'skip:> 20': 0.16; 'usable': 0.16; 'index': 0.16; 'sat,': 0.16; '(where': 0.19; 'stack': 0.19; 'starts': 0.20; 'fit': 0.20; 'appears': 0.22; 'mind.': 0.24; 'url:home': 0.24; 'mention': 0.26; 'header:X-Complaints-To:1': 0.27; 'function': 0.29; "doesn't": 0.30; "i'm": 0.30; 'becoming': 0.31; 'block,': 0.31; 'work:': 0.31; 'quite': 0.32; 'style': 0.33; 'could': 0.34; 'problem': 0.35; 'operations': 0.35; 'point.': 0.35; 'but': 0.35; 'false': 0.36; 'charset:us-ascii': 0.36; 'application': 0.37; 'too': 0.37; 'list': 0.37; 'being': 0.38; 'form,': 0.38; 'to:addr:python-list': 0.38; 'expect': 0.39; 'does': 0.39; 'to:addr:python.org': 0.39; 'either': 0.39; 'received:org': 0.40; 'even': 0.60; 'more': 0.64; 'reverse': 0.68; 'evaluate': 0.72; 'batchelder': 0.84; 'functions)': 0.84; 'overall,': 0.84; 'them)': 0.84; 'viable': 0.84; 'subject::': 0.85; 'drops': 0.91; 'lazy': 0.91; 'received:108': 0.93 X-Injected-Via-Gmane: http://gmane.org/ To: python-list@python.org From: Dennis Lee Bieber Subject: Re: (test) ? a:b Date: Sat, 25 Oct 2014 14:11:56 -0400 Organization: IISS Elusive Unicorn References: <7d2ea3c1-504e-4f5c-8338-501b1483df38@googlegroups.com> <878uk6x5nd.fsf@elektro.pacujo.net> <544a1016$0$13000$c3e8da3$5496439d@news.astraweb.com> <544b2f15$0$12978$c3e8da3$5496439d@news.astraweb.com> Mime-Version: 1.0 Content-Type: text/plain; charset=us-ascii Content-Transfer-Encoding: 7bit X-Gmane-NNTP-Posting-Host: adsl-108-79-218-175.dsl.klmzmi.sbcglobal.net X-Newsreader: Forte Agent 6.00/32.1186 X-No-Archive: YES 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: 55 NNTP-Posting-Host: 2001:888:2000:d::a6 X-Trace: 1414260726 news.xs4all.nl 2938 [2001:888:2000:d::a6]:33508 X-Complaints-To: abuse@xs4all.nl Xref: csiph.com comp.lang.python:79676 On Sat, 25 Oct 2014 07:58:14 -0400, Ned Batchelder declaimed the following: > >You mention "standard Python idioms." I think this style of >conditional-via-indexing is becoming quite uncommon, and is no longer >one of the standard Python idioms. This is now in the category of >"outdated hack." > That may be true for the case where the index is based upon a Boolean expression... But the general form is still viable for either numeric indices (table of functions) and switch/case style operations (replace the list with a dictionary). The Boolean application is merely a specialization of a more general idiom. The "true if cond else false" just doesn't fit my mind. Even HP RPL (where one might expect strangeness) uses if cond then true else false end though being reverse polish overall, one could write cond if then true else false end as "if" merely starts the block, and it is the "then" which evaluates the condition, whose value is still the top of stack at that point. I'm too lazy to see if one could do false true cond if then else end which does have the problem of evaluating both false and true paths -- but if no side-effects, might work: the "then" pulls the "cond", if true the "else" takes the "true" and the "end" drops the "false" (and if "false" the "else" drops the "true" and the "end" takes the "false")... The more in-line form, usable outside of RPL appears as a function ifte(cond, true, false) which wasn't wanted for Python as it would evaluate both true and false (no lazy evaluation; one would need to make a lambda for them) -- Wulfraed Dennis Lee Bieber AF6VN wlfraed@ix.netcom.com HTTP://wlfraed.home.netcom.com/