Groups | Search | Server Info | Keyboard shortcuts | Login | Register [http] [https] [nntp] [nntps]


Groups > comp.lang.python > #31047

RE: RE: Unpaking Tuple

From "Prasad, Ramit" <ramit.prasad@jpmorgan.com>
Subject RE: RE: Unpaking Tuple
Date 2012-10-09 16:40 +0000
References <801f0e2c-7d1d-4e91-bec5-78c5e53a70ec@googlegroups.com> <mailman.1973.1349736270.27098.python-list@python.org> <adht95F2luqU1@mid.individual.net>
Newsgroups comp.lang.python
Message-ID <mailman.2010.1349800838.27098.python-list@python.org> (permalink)

Show all headers | View raw


Bob Martin wrote
> in 682592 20121008 232126 "Prasad, Ramit" <ramit.prasad@jpmorgan.com> wrote:
> >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
> 
> How does one unpack this post?  ;-)
> --

Hmm, I am not sure why that happened. For reference: 
http://mail.python.org/pipermail/python-list/2012-October/632603.html
This email is confidential and subject to important disclaimers and
conditions including on offers for the purchase or sale of
securities, accuracy and completeness of information, viruses,
confidentiality, legal privilege, and legal entity disclaimers,
available at http://www.jpmorgan.com/pages/disclosures/email.  

Back to comp.lang.python | Previous | NextPrevious in thread | Next in thread | Find similar | Unroll thread


Thread

Unpaking Tuple sajuptpm <sajuptpm@gmail.com> - 2012-10-06 03:09 -0700
  Re: Unpaking Tuple Chris Rebert <clp2@rebertia.com> - 2012-10-06 03:27 -0700
    Re: Unpaking Tuple Roy Smith <roy@panix.com> - 2012-10-06 08:46 -0400
      Re: Unpaking Tuple Steven D'Aprano <steve+comp.lang.python@pearwood.info> - 2012-10-06 15:08 +0000
        Re: Unpaking Tuple Thomas Bach <thbach@students.uni-mainz.de> - 2012-10-08 23:45 +0200
        RE: Unpaking Tuple "Prasad, Ramit" <ramit.prasad@jpmorgan.com> - 2012-10-08 22:21 +0000
          Re: RE: Unpaking Tuple Bob Martin <bob.martin@excite.com> - 2012-10-09 07:07 +0100
            Re: Unpaking Tuple Dave Angel <d@davea.name> - 2012-10-09 02:29 -0400
              Re: Unpaking Tuple Jussi Piitulainen <jpiitula@ling.helsinki.fi> - 2012-10-09 10:22 +0300
                Re: mangled messages (was: Unpaking Tuple) Tim Chase <python.list@tim.thechases.com> - 2012-10-09 05:48 -0500
                Re: mangled messages (was: Unpaking Tuple) Jussi Piitulainen <jpiitula@ling.helsinki.fi> - 2012-10-09 15:05 +0300
                Re: mangled messages Tim Chase <python.list@tim.thechases.com> - 2012-10-09 09:26 -0500
            Re: Unpaking Tuple Grant Edwards <invalid@invalid.invalid> - 2012-10-09 14:11 +0000
            RE: RE: Unpaking Tuple "Prasad, Ramit" <ramit.prasad@jpmorgan.com> - 2012-10-09 16:40 +0000
            Re: Unpaking Tuple Robert Miles <robertmiles@teranews.com> - 2012-11-18 19:14 -0600
            Re: Unpaking Tuple Hans Mulder <hansmu@xs4all.nl> - 2012-11-19 02:56 +0100
  Re: Unpaking Tuple woooee <woooee@gmail.com> - 2012-10-07 10:58 -0700
    Re: Unpaking Tuple Terry Reedy <tjreedy@udel.edu> - 2012-10-07 16:03 -0400

csiph-web