Path: csiph.com!x330-a1.tempe.blueboxinc.net!usenet.pasdenom.info!aioe.org!feeder.news-service.com!newsfeed.xs4all.nl!newsfeed5.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.000 X-Spam-Evidence: '*H*': 1.00; '*S*': 0.00; 'assigning': 0.07; 'infinite': 0.07; 'count.': 0.09; 'counting': 0.09; 'targets.': 0.09; 'ugly': 0.09; 'syntax': 0.11; 'am,': 0.13; 'wrote:': 0.15; '"and': 0.16; '-tkc': 0.16; 'comma': 0.16; 'from:addr:python.list': 0.16; 'from:addr:tim.thechases.com': 0.16; 'from:name:tim chase': 0.16; 'iterator.': 0.16; 'justify': 0.16; 'message-id:@tim.thechases.com': 0.16; 'py3k': 0.16; 'py3k,': 0.16; 'received:70.251': 0.16; 'received:dsl.rcsntx.swbell.net': 0.16; 'received:rcsntx.swbell.net': 0.16; 'received:swbell.net': 0.16; 'subject: \n ': 0.16; 'case.': 0.16; 'cc:addr:python-list': 0.16; 'written': 0.17; '2.x': 0.19; 'happening': 0.19; 'slightly': 0.19; 'cc:2**0': 0.21; 'cc:no real name:2**0': 0.22; "doesn't": 0.22; 'header:In-Reply-To:1': 0.22; 'later': 0.26; '(and': 0.27; 'lists': 0.29; 'cc:addr:python.org': 0.30; 'disappointed': 0.30; 'subject:?': 0.31; 'seem': 0.31; 'rather': 0.33; 'header:User- Agent:1': 0.34; 'there': 0.34; 'however,': 0.34; 'force': 0.34; 'things': 0.34; 'assignment': 0.35; 'doing': 0.37; 'but': 0.37; 'using': 0.37; 'subject:: ': 0.38; 'steven': 0.38; 'something': 0.38; 'perhaps': 0.39; 'prevent': 0.40; 'sense': 0.40; 'target': 0.61; 'special': 0.67; 'subject:one': 0.77; 'generator,': 0.84; 'subject:value': 0.84; 'ugly,': 0.84; 'complexity': 0.93 Date: Wed, 03 Aug 2011 06:15:46 -0500 From: Tim Chase User-Agent: Mozilla/5.0 (X11; U; Linux i686; en-US; rv:1.9.2.18) Gecko/20110616 Thunderbird/3.1.11 MIME-Version: 1.0 To: Steven D'Aprano Subject: Re: Syntactic sugar for assignment statements: one value to multiple targets? References: <16ea4848-db0c-489a-968c-ca40700f5806@m5g2000prh.googlegroups.com> <4e39060f$0$29988$c3e8da3$5496439d@news.astraweb.com> In-Reply-To: <4e39060f$0$29988$c3e8da3$5496439d@news.astraweb.com> Content-Type: text/plain; charset=ISO-8859-1; format=flowed Content-Transfer-Encoding: 7bit X-AntiAbuse: This header was added to track abuse, please include it with any abuse report X-AntiAbuse: Primary Hostname - boston.accountservergroup.com X-AntiAbuse: Original Domain - python.org X-AntiAbuse: Originator/Caller UID/GID - [47 12] / [47 12] X-AntiAbuse: Sender Address Domain - tim.thechases.com X-Source: X-Source-Args: X-Source-Dir: 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: 41 NNTP-Posting-Host: 2001:888:2000:d::a6 X-Trace: 1312370157 news.xs4all.nl 23864 [2001:888:2000:d::a6]:37822 X-Complaints-To: abuse@xs4all.nl Xref: x330-a1.tempe.blueboxinc.net comp.lang.python:10800 On 08/03/2011 03:25 AM, Steven D'Aprano wrote: > gc wrote: > >> Target lists using comma separation are great, but they don't work >> very well for this task. What I want is something like >> >> a,b,c,d,e = *dict() > > > a, b, c, d, e = [dict() for i in range(5)] > > Unfortunately there is no way of doing so without counting the assignment > targets. While slightly ugly, it doesn't seem ugly enough to justify the > extra complexity of special syntax for such a special case. I understand that in Py3k (and perhaps back-ported into later 2.x series?) one can do something like a, b, c, d, e, *junk = (dict() for _ in range(9999)) to prevent the need to count. However, I was disappointed with all the generator-ification of things in Py3k, that this "and the rest" syntax slurps up the entire generator, rather than just assigning the iterator. That would much more tidily be written as a,b,c,d,e, *more_dict_generator = (dict() for _ in itertools.count()) (itertools.count() happening to be a infinite generator). I can see the need to slurp if you have things afterward: a,b,c, *junk ,d,e = iterator(...) but when the "and the rest" is the last one, it would make sense not to force a slurp. -tkc