Path: csiph.com!au2pb.net!feeder.erje.net!1.eu.feeder.erje.net!newsfeed.xs4all.nl!newsfeed7.news.xs4all.nl!news.tele.dk!news.tele.dk!small.news.tele.dk!newsgate.cistron.nl!newsgate.news.xs4all.nl!nzpost1.xs4all.net!not-for-mail Return-Path: X-Original-To: python-list@python.org Delivered-To: python-list@mail.python.org X-Spam-Status: OK 0.026 X-Spam-Evidence: '*H*': 0.95; '*S*': 0.00; 'indexing': 0.07; 'cc:addr :python-list': 0.09; 'subject:python': 0.14; 'evaluates': 0.16; 'from:addr:rosuav': 0.16; 'from:name:chris angelico': 0.16; 'operator.': 0.16; 'semantically': 0.16; 'ternary': 0.16; 'wrote:': 0.16; '2015': 0.20; 'cc:2**0': 0.20; 'cc:addr:python.org': 0.20; 'names.': 0.22; 'sep': 0.22; 'am,': 0.23; 'second': 0.24; 'header:In-Reply-To:1': 0.24; 'fri,': 0.27; 'message-id:@mail.gmail.com': 0.27; 'list': 0.34; 'received:google.com': 0.35; 'false': 0.35; 'instead': 0.36; 'subject:: ': 0.37; 'of:': 0.66; "they're": 0.66; 'evaluate': 0.72; 'chrisa': 0.84; 'todd': 0.84; 'to:none': 0.91; 'careful': 0.91 DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=gmail.com; s=20120113; h=mime-version:in-reply-to:references:date:message-id:subject:from:cc :content-type; bh=JBordqougQuN1uQxiQ3Br49gksv+RYQ7TlSgajnTsL8=; b=KEYDPF42wSBRqNUQkj5REKXckOMzMs141kt21PO37kVLMdGUv+YCdUx63oukVVNWtI 9dqnmYIEolmtC3yDQJjl5K/ptH9XC8mrFMQrQXJjiInaQyP9vXN6ycaUgHdKoyBnLf/y Iy7hkLa8i8USed/rV2Vte+i3nYn5q0Jjp5i4mSCAOnPHFxqYzrFLgl2ADl7HBBKz88XX oSwebU86ImF7YNNGbkEGTEhhi2Xl3ArU+r6wGIhqybiG0hUw21POh0ZNGpu8h9HDsNC+ MElt2V+qp7/LiLsiuA5juYNuauqmViJfM+DA+9AahXmN9+IatbMxIwxD9+NikySuLWbZ SCrw== MIME-Version: 1.0 X-Received: by 10.50.178.145 with SMTP id cy17mr31681968igc.92.1443113874282; Thu, 24 Sep 2015 09:57:54 -0700 (PDT) In-Reply-To: References: <560391ea$0$2885$c3e8da3$76491128@news.astraweb.com> Date: Fri, 25 Sep 2015 02:57:54 +1000 Subject: Re: Idiosyncratic python From: Chris Angelico Cc: "python-list@python.org" Content-Type: text/plain; charset=UTF-8 X-BeenThere: python-list@python.org X-Mailman-Version: 2.1.20+ 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: 15 NNTP-Posting-Host: 2001:888:2000:d::a6 X-Trace: 1443113877 news.xs4all.nl 23844 [2001:888:2000:d::a6]:56820 X-Complaints-To: abuse@xs4all.nl Xref: csiph.com comp.lang.python:97081 On Fri, Sep 25, 2015 at 2:54 AM, Todd wrote: > Using list indexing with booleans in place of a ternary operator. > > a = False > b = [var2, var1][a] > > Instead of: > > b = var1 if a else var2 Be careful - these are not semantically identical. The first one evaluates both var1 and var2, while the second will evaluate only the one it needs. This might be significant if they're not simple names. ChrisA