Path: csiph.com!x330-a1.tempe.blueboxinc.net!usenet.pasdenom.info!aioe.org!feeder.news-service.com!newsfeed.xs4all.nl!newsfeed6.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.002 X-Spam-Evidence: '*H*': 1.00; '*S*': 0.00; 'subject:: [': 0.03; 'args': 0.07; 'defaults': 0.07; 'subject:()': 0.09; 'pm,': 0.11; 'wrote:': 0.14; 'be?': 0.16; 'blah': 0.16; 'clobber': 0.16; 'rantingrick': 0.16; 'redundancy': 0.16; 'removed:': 0.16; 'settle': 0.16; 'vals': 0.16; 'subject:] ': 0.16; 'subject:skip:d 10': 0.18; 'url:blog': 0.18; 'cc:no real name:2**0': 0.20; 'cc:2**0': 0.20; 'cheers,': 0.20; 'header:In-Reply-To:1': 0.22; 'cc:addr:python-list': 0.22; 'mon,': 0.22; 'specified': 0.22; 'chris': 0.27; 'message-id:@mail.gmail.com': 0.28; "doesn't": 0.28; 'assuming': 0.29; 'list': 0.30; 'cc:addr:python.org': 0.31; 'skip:\xc2 20': 0.31; 'none': 0.36; 'case': 0.37; 'should': 0.37; 'apr': 0.38; 'received:google.com': 0.38; 'anything': 0.38; 'to.': 0.39; 'set': 0.39; 'would': 0.40; 'header:Received:5': 0.40; '2011': 0.62; 'needing': 0.68; 'received:74.125.83': 0.69; 'subject:Request': 0.73; '11,': 0.77; 'swap': 0.84 DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=rebertia.com; s=google; h=domainkey-signature:mime-version:sender:in-reply-to:references:date :x-google-sender-auth:message-id:subject:from:to:cc:content-type :content-transfer-encoding; bh=4h2sctDYeh34atrY7gYoOThgV0ul5ABqxw1R8gfjXeU=; b=X2MHjhD0yhmJEYb5R+jYG/a0sa5pJQhoR5vCEoCULnra8fuj120gkGrP95pS63Xs7y 0+loKsbLd5mjopr8dlg9qTfyS+KM8v4AkBpCnRzVAfyD5Fwapm4MD3xGnJu1Y75E730z WM/UODdVZYrGgGG9H0PTnuszpDUbv1O/EAs9Y= DomainKey-Signature: a=rsa-sha1; c=nofws; d=rebertia.com; s=google; h=mime-version:sender:in-reply-to:references:date :x-google-sender-auth:message-id:subject:from:to:cc:content-type :content-transfer-encoding; b=MvE4pPPXvqevG5Z6M/a0mT5ZLMDqyzTyGXQNANetwEqnl2v1dzDhcBlvZNuNqa/Wpo h/PXudxbMjlAqqskoiFriO5NQXU+NT5jUzqGo5t6QB8hzJJNi7gtyEXTn0AF2N/iGQDH n81+XVQIaAKAs9yhrsL0+xv40q9GIIkiFYSf8= MIME-Version: 1.0 Sender: chris@rebertia.com In-Reply-To: <48897e75-c02c-43c7-9f46-39da4bcc406d@p16g2000vbi.googlegroups.com> References: <48897e75-c02c-43c7-9f46-39da4bcc406d@p16g2000vbi.googlegroups.com> Date: Mon, 11 Apr 2011 15:53:45 -0700 X-Google-Sender-Auth: 8pIUirF5ejgS_JfYOMx2-8Wex4Q Subject: Re: [Feature Request] dict.setdefault() From: Chris Rebert To: rantingrick Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: quoted-printable Cc: python-list@python.org X-BeenThere: python-list@python.org X-Mailman-Version: 2.1.12 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: 32 NNTP-Posting-Host: 82.94.164.166 X-Trace: 1302562429 news.xs4all.nl 81475 [::ffff:82.94.164.166]:37323 X-Complaints-To: abuse@xs4all.nl Xref: x330-a1.tempe.blueboxinc.net comp.lang.python:3000 On Mon, Apr 11, 2011 at 2:35 PM, rantingrick wrote: > > setdefault should take **kw args in the case of needing to set > multiple defaults at one time. I would even settle for an *arg list if > i had to. What would the return value be? dict.setdefault() doesn't currently just return None you know. > Anything is better than... > > d.setdefault(blah, blah) > d.setdefault(blah, blah) > d.setdefault(blah, blah) > d.setdefault(blah, blah) > if blah is not blah: > =C2=A0 =C2=A0d.setdefault(blah, blah) The redundancy is easily removed: defaults =3D {blah: blah, blah: blah, blah: blah, blah: blah} defaults.update(d) # clobber defaults with specified vals d =3D defaults # swap in, assuming not aliased # if aliased, then instead: # d.clear() # d.update(defaults) if blah is not blah: d.setdefault(blah, blah) Cheers, Chris -- http://blog.rebertia.com