Reverse zip() ?

Andreas Waldenburger geekmail at usenot.de
Tue Dec 2 15:44:02 EST 2008


On Tue, 02 Dec 2008 21:12:19 +0100 Stefan Behnel <stefan_ml at behnel.de>
wrote:
> Andreas Waldenburger wrote:
> > [snip]
> > This is of course trivial to do via iteration or listcomps, BUT, I
> > was wondering if there is a function I don't know about that does
> > this nicely?
> 
> I think you're asking about zip():
> 
> 	>>> l=[1,2,3]
> 	>>> zip(l,l)
> 	[(1, 1), (2, 2), (3, 3)]
> 	>>> zip(*zip(l,l))
> 	[(1, 2, 3), (1, 2, 3)]
> 
So I am. That sure was weird.

Thanks for the quick and somewhat surreal help. Need I say that between
posting this question and reading your reply I set out to implement
this wonder-function?
:)

/W



-- 
My real email address is constructed by swapping the domain with the
recipient (local part).



More information about the Python-list mailing list