Path: csiph.com!usenet.pasdenom.info!news.redatomik.org!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.003 X-Spam-Evidence: '*H*': 0.99; '*S*': 0.00; '"this': 0.03; '"if': 0.09; 'none):': 0.09; 'parameter': 0.09; 'received:80.91': 0.09; 'received:80.91.229': 0.09; 'received:gmane.org': 0.09; 'received:list': 0.09; 'worked,': 0.09; 'def': 0.12; 'wrote': 0.14; '"things': 0.16; 'called,': 0.16; 'effect.': 0.16; 'on"': 0.16; 'received:80.91.229.3': 0.16; 'received:plane.gmane.org': 0.16; 'zero.': 0.16; ':-)': 0.16; 'thanks,': 0.17; 'wrote:': 0.18; 'code.': 0.18; 'passing': 0.19; 'solution.': 0.20; 'issue,': 0.24; "i've": 0.25; 'least': 0.26; 'header:X-Complaints-To:1': 0.27; 'function': 0.29; "skip:' 10": 0.31; 'overhead': 0.31; 'probably': 0.32; 'stuff': 0.32; 'test': 0.35; 'but': 0.35; 'method': 0.36; 'subject:?': 0.36; 'changing': 0.37; 'application': 0.37; 'mapping': 0.38; 'to:addr:python-list': 0.38; 'does': 0.39; 'to:addr:python.org': 0.39; 'received:org': 0.40; 'most': 0.60; 'become': 0.64; 'chance': 0.65; 'frank': 0.68; 'default': 0.69; 'therefore': 0.72; 'operated': 0.74; 'skip:n 40': 0.81; 'subject:this': 0.83; 'idiom': 0.84; 'absolutely': 0.87 X-Injected-Via-Gmane: http://gmane.org/ To: python-list@python.org From: "Frank Millman" Subject: Re: Is this unpythonic? Date: Sat, 9 May 2015 11:10:00 +0200 References: <554c8b0a$0$12992$c3e8da3$5496439d@news.astraweb.com> <554cd119$0$12977$c3e8da3$5496439d@news.astraweb.com> X-Gmane-NNTP-Posting-Host: 197.89.68.193 X-MSMail-Priority: Normal X-Newsreader: Microsoft Outlook Express 6.00.3790.4657 X-MimeOLE: Produced By Microsoft MimeOLE V6.00.3790.4913 X-RFC2646: Format=Flowed; Response 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: 42 NNTP-Posting-Host: 2001:888:2000:d::a6 X-Trace: 1431162609 news.xs4all.nl 2873 [2001:888:2000:d::a6]:52022 X-Complaints-To: abuse@xs4all.nl Xref: csiph.com comp.lang.python:90222 "Gregory Ewing" wrote in message news:cr5sc6FgfmiU1@mid.individual.net... > Frank Millman wrote: > > The absolutely clearest way to write it would > probably be > > def f(things = None): > "things is a mapping of stuff to be operated on" > if things: > for key in things: > value = things[key] > ... > > A default value of None is a well-established idiom > for "this parameter is optional", and "if x:" is > idiomatic for "if I've been given an x", so writing it > that way has the best chance of passing the "pretty much > what you expect" test for good code. :-) > Thanks, Greg, that makes a lot of sense. My original method of using 'z=[]' worked, but would cause a reviewer to stop and think about it for a moment. Changing it to 'z=()' would have pretty much the same effect. Using 'z=None' would cause the least hesitation, and is therefore I think the most pythonic. It does require an additional test every time the function is called, but the effect of that in my application is virtually zero. If the overhead did become an issue, Dave's suggestion of 'z=EMPTY_LIST' would be a good solution. Frank