Path: csiph.com!v102.xanadu-bbs.net!xanadu-bbs.net!goblin1!goblin2!goblin.stu.neva.ru!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; 'url:pipermail': 0.05; 'clause': 0.07; 'completeness': 0.07; 'python': 0.09; 'received:155': 0.09; 'reference:': 0.09; 'unpack': 0.09; ';-)': 0.11; 'sat,': 0.15; 'disclaimers': 0.16; 'disclaimers,': 0.16; 'from:addr:jpmorgan.com': 0.16; 'head,': 0.16; 'oct': 0.16; 'received:155.180': 0.16; 'received:159.53': 0.16; 'received:159.53.110': 0.16; 'received:159.53.110.174': 0.16; 'received:169.70': 0.16; 'received:169.70.184': 0.16; 'received:bankone.net': 0.16; 'received:exchad.jpmchase.net': 0.16; 'received:jpmchase.com': 0.16; 'received:jpmchase.net': 0.16; 'received:sj2.jpmchase.com': 0.16; 'received:svr.bankone.net': 0.16; 'securities,': 0.16; 'skip:) 30': 0.16; 'stumbled': 0.16; 'url:disclosures': 0.16; 'url:jpmorgan': 0.16; 'martin': 0.16; 'wrote:': 0.17; '>>>': 0.18; 'skip:v 30': 0.20; 'to:name:python-list@python.org': 0.20; 'please?': 0.22; 'split': 0.23; 'received:169.254': 0.24; 'header :In-Reply-To:1': 0.25; 'wrote': 0.26; 'accuracy': 0.27; 'skip:> 10': 0.27; 'skip:( 20': 0.28; "d'aprano": 0.29; 'grouping': 0.29; 'steven': 0.29; 'tail': 0.29; 'wrap': 0.29; 'received:169': 0.29; "skip:' 10": 0.30; 'header:Received:8': 0.30; 'code': 0.31; 'url:python': 0.32; 'skip:- 10': 0.32; 'to:addr:python-list': 0.33; 'skip:d 20': 0.34; 'url:org': 0.36; 'charset:us-ascii': 0.36; 'does': 0.37; 'why': 0.37; 'subject:: ': 0.38; 'sure': 0.38; 'to:addr:python.org': 0.39; 'help': 0.40; 'url:mail': 0.40; 'think': 0.40; 'skip:n 10': 0.63; 'information,': 0.63; 'url:email': 0.63; 'it!': 0.64; 'legal': 0.65; 'subject': 0.66; 'purchase': 0.67; 'believe': 0.69; 'sale': 0.76; 'happened.': 0.84; 'received:169.254.8': 0.84; 'bob': 0.91 X-DKIM: OpenDKIM Filter v2.1.3 sj2.jpmchase.com q99GeZ6x025708 DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=jpmorgan.com; s=smtpout; t=1349800835; bh=el/PuAgbhhq+CvjvFrpsDOUZ4NtxH1lz2t8vxdkhjgk=; h=From:To:Subject:Date:Message-ID:References:In-Reply-To: Content-Transfer-Encoding:MIME-Version:Content-Type; b=frcdn1TXU+s1x4KxsTQFTfsF4w8PyMpERrxFgtc7W0DicrPlyVg6DjN3DlCuY1N2Q hgSedr29UxcdQm6SYa3TmAPP52+qYLN33pGPqdgyJ01dVVrK0FcdUHeeEmOiAzCKvc aFrJlnRdpZ4PkvnuLQ3ezUJ7CXQBFcmFp+HEjkEo= From: "Prasad, Ramit" To: "python-list@python.org" Subject: RE: RE: Unpaking Tuple Thread-Topic: RE: Unpaking Tuple Thread-Index: AQHNpeS9EAmEdF6GNEmjF3pY0anNlJexLV8w Date: Tue, 9 Oct 2012 16:40:17 +0000 References: <801f0e2c-7d1d-4e91-bec5-78c5e53a70ec@googlegroups.com> In-Reply-To: Accept-Language: en-US Content-Language: en-US X-MS-Has-Attach: X-MS-TNEF-Correlator: x-originating-ip: [10.67.79.47] Content-Transfer-Encoding: quoted-printable MIME-Version: 1.0 X-DLP-FWD: Yes Content-Type: text/plain; charset="us-ascii" X-BeenThere: python-list@python.org X-Mailman-Version: 2.1.15 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: 37 NNTP-Posting-Host: 2001:888:2000:d::a6 X-Trace: 1349800838 news.xs4all.nl 6916 [2001:888:2000:d::a6]:35482 X-Complaints-To: abuse@xs4all.nl Xref: csiph.com comp.lang.python:31047 Bob Martin wrote=0D=0A> in 682592 20121008 232126 "Prasad, Ramit" wrote:=0D=0A> >Thomas Bach wrote:=3D0D=3D0A> Hi ther= e,=3D0D=3D0A> =3D0D=3D0A> On Sat, Oct 06, 2012 at =3D=0D=0A> >03:08:38PM +0= 000, Steven D'Aprano wrote:=3D0D=3D0A> >=3D0D=3D0A> > my_tuple =3D3D my_=3D= =0D=0A> >tuple[:4]=3D0D=3D0A> > a,b,c,d =3D3D my_tuple if len(my_tuple) =3D= 3D=3D3D 4 else (my_=3D=0D=0A> >tuple + (None,)*4)[:4]=3D0D=3D0A> >=3D0D=3D0= A> =3D0D=3D0A> Are you sure this works as y=3D=0D=0A> >ou expect? I just st= umbled over the following:=3D0D=3D0A> =3D0D=3D0A> $ python=3D0D=3D=0D=0A> >= =3D0A> Python 3=3D2E2=3D2E3 (default, Jun 25 2012, 23:10:56)=3D0D=3D0A> [GC= C 4=3D2E7=3D2E=3D=0D=0A> >1] on linux2=3D0D=3D0A> Type "help", "copyright",= "credits" or "license" for mo=3D=0D=0A> >re information=3D2E=3D0D=3D0A> >>= > split =3D3D ['foo', 'bar']=3D0D=3D0A> >>> head, tail=3D=0D=0A> >=3D3D spl= it if len(split) =3D3D=3D3D 2 else split[0], None=3D0D=3D0A> >>> head=3D0D= =3D0A=3D=0D=0A> >> ['foo', 'bar']=3D0D=3D0A> >>> tail=3D0D=3D0A> >>>=3D0D= =3D0A> =3D0D=3D0A> I don't get it! =3D=0D=0A> >Could someone help me, pleas= e? Why is head not 'foo'=3D0D=3D0A> and tail not 'b=3D=0D=0A> >ar'?=3D0D=3D= 0A> =3D0D=3D0A> Regards,=3D0D=3D0A> Thomas=3D0D=3D0A> --=3D0D=3D0A=3D0D=3D= 0AI think yo=3D=0D=0A> >u just need to wrap the else in parenthesis so the= =3D0D=3D0Aelse clause is trea=3D=0D=0A> >ted as a tuple=3D2E Without the pa= renthesis =3D0D=3D0AI believe it is grouping th=3D=0D=0A> >e code like this= =3D2E=3D0D=3D0A=3D0D=3D0Ahead, tail =3D3D (split if len(split) =3D3D=3D3D 2= =3D=0D=0A> >else split[0] ), None=3D0D=3D0A=3D0D=3D0AYou want:=3D0D=3D0Ahea= d, tail =3D3D split if le=3D=0D=0A> >n(split) =3D3D=3D3D 2 else (split[0], = None )=3D0D=3D0A=3D0D=3D0A=3D0D=3D0ARamit=3D0D=3D0AThis e=3D=0D=0A> >mail i= s confidential and subject to important disclaimers and=3D0D=3D0Aconditio= =3D=0D=0A> >ns including on offers for the purchase or sale of=3D0D=3D0Asec= urities, accurac=3D=0D=0A> >y and completeness of information, viruses,=3D0= D=3D0Aconfidentiality, legal pri=3D=0D=0A> >vilege, and legal entity discla= imers,=3D0D=3D0Aavailable at http://www=3D2Ejpmorg=3D=0D=0A> >an=3D2Ecom/pa= ges/disclosures/email=3D2E=0D=0A> =0D=0A> How does one unpack this post? ;= -)=0D=0A> --=0D=0A=0D=0AHmm, I am not sure why that happened=2E For referen= ce: =0D=0Ahttp://mail=2Epython=2Eorg/pipermail/python-list/2012-October/632= 603=2Ehtml=0D=0AThis email is confidential and subject to important disclai= mers and=0D=0Aconditions including on offers for the purchase or sale of=0D= =0Asecurities, accuracy and completeness of information, viruses,=0D=0Aconf= identiality, legal privilege, and legal entity disclaimers,=0D=0Aavailable = at http://www=2Ejpmorgan=2Ecom/pages/disclosures/email=2E