Path: csiph.com!newsfeed.hal-mli.net!feeder3.hal-mli.net!newsfeed.hal-mli.net!feeder1.hal-mli.net!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.001 X-Spam-Evidence: '*H*': 1.00; '*S*': 0.00; 'clause': 0.07; 'completeness': 0.07; 'python': 0.09; 'received:155': 0.09; 'tuple.': 0.09; 'sat,': 0.15; "'bar']": 0.16; 'disclaimers': 0.16; 'disclaimers,': 0.16; 'from:addr:jpmorgan.com': 0.16; 'head,': 0.16; 'oct': 0.16; 'received:155.180': 0.16; 'received:155.180.234': 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; 'stumbled': 0.16; 'url:disclosures': 0.16; 'url:jpmorgan': 0.16; 'wrote:': 0.17; '>>>': 0.18; '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; 'accuracy': 0.27; "d'aprano": 0.29; 'grouping': 0.29; 'steven': 0.29; 'tail': 0.29; 'wrap': 0.29; 'received:169': 0.29; 'this.': 0.29; 'header:Received:8': 0.30; 'code': 0.31; 'could': 0.32; 'to:addr:python-list': 0.33; 'charset :us-ascii': 0.36; 'why': 0.37; 'subject:: ': 0.38; 'sure': 0.38; 'there,': 0.38; 'to:addr:python.org': 0.39; 'help': 0.40; 'think': 0.40; 'thomas': 0.62; 'information,': 0.63; 'url:email': 0.63; 'more': 0.63; 'it!': 0.64; 'legal': 0.65; 'subject': 0.66; 'purchase': 0.67; 'believe': 0.69; 'sale': 0.76; "'foo'": 0.84; 'received:169.254.8': 0.84 X-DKIM: OpenDKIM Filter v2.1.3 sj2.jpmchase.com q98MLXwD027152 DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=jpmorgan.com; s=smtpout; t=1349734893; bh=J+bDKdQMfcopIMT9Gzf3s5NYi4USo0bCBLFAmLg+S/s=; h=From:To:Subject:Date:Message-ID:References:In-Reply-To: Content-Transfer-Encoding:MIME-Version:Content-Type; b=HJ4S7GJiYLb2ETLvwauB8QchjrfNELAiYLECRCgekNy1AXwXkX4Oohvsi1D1FtrQs vlQBsK58chzKM0KF8zvw4jcpIEykjVETpOivNF2fUigvy4LQ/bjLpL0gPLvjEKNBV7 S85FsxFYlGvAmDwzinUhd+1ktiJwsc3X4FeSaNaw= From: "Prasad, Ramit" To: "python-list@python.org" Subject: RE: Unpaking Tuple Thread-Topic: Unpaking Tuple Thread-Index: AQHNpZ6PrkwPsXJPfEKA6ThSYOz5lpev+P9w Date: Mon, 8 Oct 2012 22:21:26 +0000 References: <801f0e2c-7d1d-4e91-bec5-78c5e53a70ec@googlegroups.com> <50704975$0$29978$c3e8da3$5496439d@news.astraweb.com> <20121008214558.GB4069@taris.box> In-Reply-To: <20121008214558.GB4069@taris.box> 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: 22 NNTP-Posting-Host: 2001:888:2000:d::a6 X-Trace: 1349736270 news.xs4all.nl 6949 [2001:888:2000:d::a6]:33816 X-Complaints-To: abuse@xs4all.nl Xref: csiph.com comp.lang.python:30980 Thomas Bach wrote:=0D=0A> Hi there,=0D=0A> =0D=0A> On Sat, Oct 06, 2012 at = 03:08:38PM +0000, Steven D'Aprano wrote:=0D=0A> >=0D=0A> > my_tuple =3D my_= tuple[:4]=0D=0A> > a,b,c,d =3D my_tuple if len(my_tuple) =3D=3D 4 else (my_= tuple + (None,)*4)[:4]=0D=0A> >=0D=0A> =0D=0A> Are you sure this works as y= ou expect? I just stumbled over the following:=0D=0A> =0D=0A> $ python=0D= =0A> Python 3=2E2=2E3 (default, Jun 25 2012, 23:10:56)=0D=0A> [GCC 4=2E7=2E= 1] on linux2=0D=0A> Type "help", "copyright", "credits" or "license" for mo= re information=2E=0D=0A> >>> split =3D ['foo', 'bar']=0D=0A> >>> head, tail= =3D split if len(split) =3D=3D 2 else split[0], None=0D=0A> >>> head=0D=0A= > ['foo', 'bar']=0D=0A> >>> tail=0D=0A> >>>=0D=0A> =0D=0A> I don't get it! = Could someone help me, please? Why is head not 'foo'=0D=0A> and tail not 'b= ar'?=0D=0A> =0D=0A> Regards,=0D=0A> Thomas=0D=0A> --=0D=0A=0D=0AI think yo= u just need to wrap the else in parenthesis so the=0D=0Aelse clause is trea= ted as a tuple=2E Without the parenthesis =0D=0AI believe it is grouping th= e code like this=2E=0D=0A=0D=0Ahead, tail =3D (split if len(split) =3D=3D 2= else split[0] ), None=0D=0A=0D=0AYou want:=0D=0Ahead, tail =3D split if le= n(split) =3D=3D 2 else (split[0], None )=0D=0A=0D=0A=0D=0ARamit=0D=0AThis e= mail is confidential and subject to important disclaimers and=0D=0Aconditio= ns including on offers for the purchase or sale of=0D=0Asecurities, accurac= y and completeness of information, viruses,=0D=0Aconfidentiality, legal pri= vilege, and legal entity disclaimers,=0D=0Aavailable at http://www=2Ejpmorg= an=2Ecom/pages/disclosures/email=2E