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


Groups > comp.lang.python > #19088

Re: unzip function?

References <jf6l7v$m3k$1@dough.gmane.org> <CAO+9iGfC60mJFgFwJNBEDE+bx4zkNUEunMAg3urCN-3RJd0g7Q@mail.gmail.com> <CAO+9iGcG_=xhVP1W=TRJo6fSCTNPQJ4cvsiYHRi5c7_fmJs-vQ@mail.gmail.com> <CABRP1o-pfRfZm6Mde_LNukYvkm+dvjhysemD=Q_VoTaa4WXQ6g@mail.gmail.com>
Date 2012-01-18 07:38 -0800
Subject Re: unzip function?
From Chris Rebert <clp2@rebertia.com>
Newsgroups comp.lang.python
Message-ID <mailman.4834.1326901142.27778.python-list@python.org> (permalink)

Show all headers | View raw


On Wed, Jan 18, 2012 at 7:31 AM, Rodrick Brown <rodrick.brown@gmail.com> wrote:
> On Wed, Jan 18, 2012 at 10:27 AM, Alec Taylor <alec.taylor6@gmail.com>
> wrote:
>>
>> http://docs.python.org/library/functions.html
>> >>> x = [1, 2, 3]
>> >>> y = [4, 5, 6]
>> >>> zipped = zip(x, y)
>> >>> zipped
>> [(1, 4), (2, 5), (3, 6)]
>> >>> x2, y2 = zip(*zipped)
>> >>> x == list(x2) and y == list(y2)
>> True
>
>
> Alec can you explain this behavior zip(*zipped)?

It's just the application of the
http://docs.python.org/tutorial/controlflow.html#unpacking-argument-lists
feature to a zip() [http://docs.python.org/library/functions.html#zip
] call.

zip(*zipped) === zip(*[(1, 4), (2, 5), (3, 6)]) === zip((1, 4), (2,
5), (3, 6)) === [(1, 2, 3), (4, 5, 6)]

Cheers,
Chris
--
http://rebertia.com

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


Thread

Re: unzip function? Chris Rebert <clp2@rebertia.com> - 2012-01-18 07:38 -0800

csiph-web