Path: csiph.com!v102.xanadu-bbs.net!xanadu-bbs.net!feeder.erje.net!eu.feeder.erje.net!feeds.phibee-telecom.net!newsfeed.xs4all.nl!newsfeed2.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.002 X-Spam-Evidence: '*H*': 1.00; '*S*': 0.00; 'else:': 0.03; 'operator': 0.03; 'none:': 0.07; 'received:80.91': 0.09; 'received:80.91.229': 0.09; 'received:gmane.org': 0.09; 'received:list': 0.09; 'jan': 0.12; 'above?': 0.16; 'non-default': 0.16; 'received:80.91.229.3': 0.16; 'received:plane.gmane.org': 0.16; 'reedy': 0.16; 'superfluous': 0.16; 'ternary': 0.16; 'values:': 0.16; 'wrote:': 0.18; 'preferred': 0.22; 'header:User-Agent:1': 0.23; 'header:X -Complaints-To:1': 0.27; 'header:In-Reply-To:1': 0.27; 'function': 0.29; 'am,': 0.29; 'code': 0.31; 'stuff': 0.32; 'something': 0.35; 'done.': 0.35; 'but': 0.35; 'there': 0.35; 'version': 0.36; 'should': 0.36; 'branch': 0.38; 'to:addr:python-list': 0.38; 'to:addr:python.org': 0.39; 'received:org': 0.40; 'received:173': 0.61; 'subject:One': 0.74; 'avoids': 0.84; 'expresses': 0.84; 'functions:': 0.84; 'received:fios.verizon.net': 0.84 X-Injected-Via-Gmane: http://gmane.org/ To: python-list@python.org From: Terry Reedy Subject: Re: One liners Date: Sat, 07 Dec 2013 16:02:26 -0500 References: <52A26763.3070803@gmail.com> <52a287cb$0$30003$c3e8da3$5496439d@news.astraweb.com> <52a30632$0$30003$c3e8da3$5496439d@news.astraweb.com> Mime-Version: 1.0 Content-Type: text/plain; charset=UTF-8; format=flowed Content-Transfer-Encoding: 7bit X-Gmane-NNTP-Posting-Host: pool-173-75-254-207.phlapa.fios.verizon.net User-Agent: Mozilla/5.0 (Windows NT 6.1; WOW64; rv:24.0) Gecko/20100101 Thunderbird/24.1.1 In-Reply-To: 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: 34 NNTP-Posting-Host: 2001:888:2000:d::a6 X-Trace: 1386450167 news.xs4all.nl 2908 [2001:888:2000:d::a6]:49303 X-Complaints-To: abuse@xs4all.nl Xref: csiph.com comp.lang.python:61255 On 12/7/2013 11:13 AM, Rotwang wrote: > On 07/12/2013 12:41, Jussi Piitulainen wrote: >> [...] >> >> if tracks is None: >> tracks = [] > > Sorry to go off on a tangent, but in my code I often have stuff like > this at the start of functions: > > tracks = something if tracks is None else tracks > > or, in the case where I don't intend for the function to be passed > non-default Falsey values: > > tracks = tracks or something > > Is there any reason why the two-line version that avoids the ternary > operator should be preferred to the above? The 'extra' line is not necessary, as one can write if tracks is None: tracks = [] # or something I prefer this because it exactly expresses what one want done. The other branch else: tracks = tracks is superfluous and to me unaesthetic. -- Terry Jan Reedy