A really bad idea.
Chad Netzer
cnetzer at mail.arc.nasa.gov
Fri Nov 15 00:15:58 EST 2002
On Thursday 14 November 2002 20:49, Paul Foley wrote:
> On Thu, 14 Nov 2002 15:33:33 -0800, Russell E Owen wrote:
> > On the other hand, I like zip just fine (though I lament the lack of an
> > unzip counterpart).
>
> Eh? Zip is its own inverse!
Hmmm...
Python 2.2.2 (#4, Oct 15 2002, 04:21:28)
>>> a = [1,2,3]
>>> b = ['a','b', 'c']
>>> zip(a,b)
[(1, 'a'), (2, 'b'), (3, 'c')]
>>> zip(zip(a,b))
[((1, 'a'),), ((2, 'b'),), ((3, 'c'),)]
>>> c,d = zip(zip(a,b))
Traceback (most recent call last):
File "<stdin>", line 1, in ?
ValueError: unpack list of wrong size
So, not quite.
But, after some thought, I see that you mean this (which is cool):
>>> c,d = zip(*zip(a,b))
>>> c
(1, 2, 3)
>>> d
('a', 'b', 'c')
ie. it's its own inverse, if you consider some extra syntax (and getting
tuples, not lists).
--
Bay Area Python Interest Group - http://www.baypiggies.net/
Chad Netzer
cnetzer at mail.arc.nasa.gov
More information about the Python-list
mailing list