Path: csiph.com!goblin3!goblin2!goblin.stu.neva.ru!newsfeed1.swip.net!uio.no!news.tele.dk!news.tele.dk!small.news.tele.dk!newsgate.cistron.nl!newsgate.news.xs4all.nl!nzpost1.xs4all.net!not-for-mail Return-Path: X-Original-To: python-list@python.org Delivered-To: python-list@mail.python.org X-Spam-Status: OK 0.001 X-Spam-Evidence: '*H*': 1.00; '*S*': 0.00; 'subject:: [': 0.03; 'cc:addr:python-list': 0.09; '(1,': 0.09; '*is*': 0.09; 'enum': 0.09; 'imho.': 0.09; 'tuple': 0.09; 'unpacking': 0.09; '*any*': 0.16; '-tkc': 0.16; 'constants': 0.16; 'constants:': 0.16; 'consume': 0.16; 'from:addr:python.list': 0.16; 'from:addr:tim.thechases.com': 0.16; 'from:name:tim chase': 0.16; 'py3': 0.16; 'sequence,': 0.16; 'wrote:': 0.16; "wouldn't": 0.16; 'variable': 0.18; '>>>': 0.20; 'cc:2**0': 0.20; 'cc:addr:python.org': 0.20; 'cc:no real name:2**0': 0.22; 'insert': 0.23; 'header:In-Reply-To:1': 0.24; 'entries': 0.27; '-----': 0.29; 'there.': 0.30; "i'd": 0.31; 'class': 0.33; 'url:python': 0.33; 'add': 0.34; 'lists': 0.34; 'list': 0.34; 'could': 0.35; 'instance': 0.35; 'something': 0.35; 'but': 0.36; 'url:org': 0.36; 'url:library': 0.36; 'received:10': 0.37; 'setting': 0.37; 'charset:us-ascii': 0.37; 'why': 0.39; 'does': 0.39; 'from:': 0.39; 'called': 0.40; 'url:3': 0.60; 'side': 0.62; 'received:50': 0.66; 'offer': 0.66; 'subject:,': 0.82; 'answer,': 0.84; 'packing': 0.84 X-Sender-Id: wwwh|x-authuser|tim@thechases.com X-Sender-Id: wwwh|x-authuser|tim@thechases.com X-MC-Relay: Neutral X-MailChannels-SenderId: wwwh|x-authuser|tim@thechases.com X-MailChannels-Auth-Id: wwwh X-MC-Loop-Signature: 1440591719069:3381823348 X-MC-Ingress-Time: 1440591719069 Date: Wed, 26 Aug 2015 07:21:34 -0500 From: Tim Chase To: Jean-Michel Pichavant Cc: python-list@python.org Subject: Re: [a,b,c,d] = 1,2,3,4 In-Reply-To: <935842626.955183.1440514765199.JavaMail.root@sequans.com> References: <935842626.955183.1440514765199.JavaMail.root@sequans.com> X-Mailer: Claws Mail 3.11.1 (GTK+ 2.24.25; x86_64-pc-linux-gnu) MIME-Version: 1.0 Content-Type: text/plain; charset=US-ASCII Content-Transfer-Encoding: 7bit X-AuthUser: tim@thechases.com 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: 51 NNTP-Posting-Host: 2001:888:2000:d::a6 X-Trace: 1440593198 news.xs4all.nl 23787 [2001:888:2000:d::a6]:50568 X-Complaints-To: abuse@xs4all.nl Xref: csiph.com comp.lang.python:95648 On 2015-08-25 16:59, Jean-Michel Pichavant wrote: > ----- Original Message ----- > > From: "Joel Goldstick" > > its called list unpacking or packing (?) > > > > the right side is considered a tuple because of the commas > > >>> a = 1,2,3 > > >>> a > > (1, 2, 3) > > >>> a[1] > > 2 > > To add to Joel's answer, the right side can be *any* sequence, and > is not restricted to lists or tuples. > > a, b, c = (x for x in range(3)) # a generator for instance Since range() *is* a generator, why not just use a, b, c = range(3) I do this often for setting constants: ( HR_FILE, PHONE_FILE, COST_CENTERS_FILE, ) = range(3) however I have to keep track of how many entries are in there. When Py3 introduced variable tuple unpacking, I'd hoped the last one wouldn't consume generators, allowing me to do something like ( HR_FILE, PHONE_FILE, COST_CENTERS, *_ ) = itertools.count() so I could insert additional constants and have the list automatically adjust. Alas, no such joy. The new Enum class does offer an auto-number functionality, but it's clunky, IMHO. https://docs.python.org/3/library/enum.html#autonumber -tkc