Path: csiph.com!x330-a1.tempe.blueboxinc.net!newsfeed.hal-mli.net!feeder1.hal-mli.net!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.006 X-Spam-Evidence: '*H*': 0.99; '*S*': 0.00; 'context': 0.04; 'from:addr:python': 0.09; 'initialized': 0.09; '16,': 0.15; '"martin': 0.16; '4:39': 0.16; 'construct.': 0.16; 'expression:': 0.16; 'from:addr:mrabarnett.plus.com': 0.16; 'from:name:mrab': 0.16; 'message-id:@mrabarnett.plus.com': 0.16; 'received:84.92': 0.16; 'received:84.92.122': 0.16; 'received:84.92.122.60': 0.16; 'received:84.93': 0.16; 'received:84.93.230': 0.16; 'reply-to:addr :python-list': 0.16; 'subject: \n ': 0.16; 'unpacking': 0.16; 'wrote:': 0.16; '>>>': 0.18; 'repeated': 0.18; "aren't": 0.21; 'maybe': 0.21; 'header:In-Reply-To:1': 0.22; 'pm,': 0.24; 'aug': 0.24; 'code': 0.25; '(the': 0.28; 'received:84': 0.28; 'example': 0.30; 'separately': 0.30; 'subject:?': 0.31; 'cases': 0.32; 'necessary.': 0.32; 'words,': 0.32; 'together.': 0.32; 'source': 0.33; 'it.': 0.33; 'there': 0.33; 'to:addr:python-list': 0.33; 'header:User-Agent:1': 0.34; 'normally': 0.34; 'all.': 0.34; 'reply-to:addr:python.org': 0.34; 'certain': 0.35; 'are.': 0.37; 'variables': 0.37; 'but': 0.37; 'something': 0.37; 'think': 0.38; 'subject:: ': 0.39; 'to:addr:python.org': 0.39; "it's": 0.40; 'where': 0.40; 'happens': 0.40; 'your': 0.61; 'stop': 0.61; 'love': 0.62; 'here': 0.65; 'destination': 0.67; 'unlimited': 0.68; 'header:Reply-To:1': 0.71; 'reply-to:no real name:2**0': 0.71; 'subject:one': 0.77; 'subject:value': 0.84 X-IronPort-Anti-Spam-Filtered: true X-IronPort-Anti-Spam-Result: ArgGAGMiS05UXebj/2dsb2JhbABBmUCPEXeBQAEBBThAEQsIEAkUAg8JAwIBAgENAjYTCAEBh266G4ZIBIteSYt3i2o Date: Wed, 17 Aug 2011 03:11:36 +0100 From: MRAB User-Agent: Mozilla/5.0 (Windows NT 5.1; rv:5.0) Gecko/20110624 Thunderbird/5.0 MIME-Version: 1.0 To: python-list@python.org Subject: Re: Syntactic sugar for assignment statements: one value to multiple targets? References: <16ea4848-db0c-489a-968c-ca40700f5806@m5g2000prh.googlegroups.com> <7f30e39b-4e4f-4426-b819-b4670871d199@df3g2000vbb.googlegroups.com> In-Reply-To: <7f30e39b-4e4f-4426-b819-b4670871d199@df3g2000vbb.googlegroups.com> Content-Type: text/plain; charset=ISO-8859-1; format=flowed Content-Transfer-Encoding: 7bit X-BeenThere: python-list@python.org X-Mailman-Version: 2.1.12 Precedence: list Reply-To: python-list@python.org 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: 29 NNTP-Posting-Host: 2001:888:2000:d::a6 X-Trace: 1313547164 news.xs4all.nl 23977 [2001:888:2000:d::a6]:52031 X-Complaints-To: abuse@xs4all.nl Xref: x330-a1.tempe.blueboxinc.net comp.lang.python:11649 On 17/08/2011 01:14, gc wrote: > On Aug 16, 4:39 pm, "Martin P. Hellwig" > wrote: >> On 03/08/2011 02:45, gc wrote: >> >> >>> a,b,c,d,e = *dict() >> >>> where * in this context means something like "assign separately to >>> all. > >> . . . it has a certain code smell to it. >> I would love to see an example where you would need such a construct. > > Perfectly reasonable request! Maybe there aren't as many cases when > multiple variables need to be initialized to the same value as I think > there are. > [snip] As I see it, there are 2 issues: 1. Repeated evaluation of an expression: "dict()" would be evaluated as many times as necessary. In other words, it's an unlimited generator. 2. Lazy unpacking: unpacking normally continues until the source is exhausted, but here you want it to stop when the destination (the RHS) is satisfied. It just happens that in your use-case they are being used together.