Path: csiph.com!x330-a1.tempe.blueboxinc.net!usenet.pasdenom.info!news.albasani.net!newsfeed.freenet.ag!news2.euro.net!newsgate.cistron.nl!newsgate.news.xs4all.nl!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; 'suppose': 0.05; 'elements.': 0.07; 'subject:based': 0.07; 'type,': 0.07; 'python': 0.08; 'doubles': 0.09; 'keys,': 0.09; 'operation,': 0.09; 'am,': 0.12; 'received:209.85.210.174': 0.13; 'received:mail- iy0-f174.google.com': 0.13; 'from:addr:rosuav': 0.16; 'from:name:chris angelico': 0.16; 'head,': 0.16; 'into.': 0.16; 'shorten': 0.16; 'subject: \n ': 0.16; 'subject:syntax': 0.16; 'unpacking.': 0.16; 'wed,': 0.17; 'wrote:': 0.18; 'trying': 0.21; 'dec': 0.22; "doesn't": 0.22; 'header:In-Reply-To:1': 0.22; 'slice': 0.23; 'do,': 0.25; 'message-id:@mail.gmail.com': 0.28; 'temporary': 0.29; 'solved': 0.30; 'tail': 0.30; 'tuples': 0.30; 'does': 0.32; 'list': 0.32; "can't": 0.32; 'instead': 0.33; 'there': 0.33; 'to:addr:python-list': 0.34; 'probably': 0.34; 'keys': 0.34; 'operations': 0.35; 'list.': 0.35; 'something': 0.35; 'subject:/': 0.35; 'else,': 0.37; 'sequence': 0.37; 'but': 0.37; 'received:google.com': 0.37; 'using': 0.38; 'steven': 0.38; 'received:209.85': 0.38; 'ways': 0.39; 'being': 0.39; "it's": 0.40; 'received:209': 0.40; 'to:addr:python.org': 0.40; 'huge': 0.61; 'type': 0.61; '2011': 0.61; 'your': 0.61; 'choose': 0.62; 'stop': 0.63; 'cost': 0.63; 'roughly': 0.67; 'it"': 0.84; 'zen': 0.84; '"one': 0.91 DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=gmail.com; s=gamma; h=mime-version:in-reply-to:references:date:message-id:subject:from:to :content-type; bh=nSjk12iyb4u4v350+xvamfFDAjmGa6lp/TpLKNs86gY=; b=yGoEuE7Uf/Gwh0U2NV0F45/1wmgcGwSkh5PfmnlV6NxyY8BCMKzbPsyiOugBxsENGD NtunrAlfG77uc6YE6eG/Df+j0TRBOIJgLVzdYYrUNO/p0YvFlflNB7+JbZ6DTB5QZbrB LsxiA6dgQNTP0DTMCs6G21FcRorh6QtPzof1c= MIME-Version: 1.0 In-Reply-To: <4efa5072$0$29973$c3e8da3$5496439d@news.astraweb.com> References: <841f4d29-f50b-4b0b-912b-b497fb6e60ec@t16g2000vba.googlegroups.com> <15424060.724.1324183952802.JavaMail.geo-discussion-forums@prix23> <55f2aab5-be87-460e-8576-645ac225c63d@l19g2000yqc.googlegroups.com> <272d2d13-3168-4991-84ed-57a255a98c10@p9g2000vbb.googlegroups.com> <99ae9ba0-4488-4b77-8e56-cf5af0d594af@cs7g2000vbb.googlegroups.com> <4ef72180$0$29973$c3e8da3$5496439d@news.astraweb.com> <4efa5072$0$29973$c3e8da3$5496439d@news.astraweb.com> Date: Wed, 28 Dec 2011 15:06:37 +1100 Subject: Re: Pythonification of the asterisk-based collection packing/unpacking syntax From: Chris Angelico To: python-list@python.org Content-Type: text/plain; charset=ISO-8859-1 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: 21 NNTP-Posting-Host: 2001:888:2000:d::a6 X-Trace: 1325045200 news.xs4all.nl 6902 [2001:888:2000:d::a6]:52804 X-Complaints-To: abuse@xs4all.nl Xref: x330-a1.tempe.blueboxinc.net comp.lang.python:18094 On Wed, Dec 28, 2011 at 10:10 AM, Steven D'Aprano wrote: > Your original use-case, where you want to change the type of tail from a > list to something else, is simply solved by one extra line of code: > > head, *tail = sequence > tail = tuple(tail) That achieves the goal of having tail as a different type, but it does have the additional cost of constructing and then discarding a temporary list. I know this is contrived, but suppose you have a huge set/frozenset using tuples as the keys, and one of your operations is to shorten all keys by removing their first elements. Current Python roughly doubles the cost of this operation, since you can't choose what type the tail is made into. But if that's what you're trying to do, it's probably best to slice instead of unpacking. Fortunately, the Zen of Python "one obvious way to do it" doesn't stop there being other ways that work too. ChrisA