List transpose method

Gerhard Häring gh_pythonlist at gmx.de
Thu Nov 1 16:45:05 EST 2001


On Thu, Nov 01, 2001 at 08:51:27PM -0200, Gustavo Niemeyer wrote:
> > Suppose I have a list like ((1,2), (3,4), (5,6)). Can some functional guru
> > tell me a one liner to transpose this to the form ((1,3,5),(2,4,6))? I can
> > only come up with an ugly multiliner.
> 
> >>> zip((1,2),(3,4),(5,6))
> [(1, 3, 5), (2, 4, 6)]

Hmm. How would I apply zip if I have a variable already, like

l = ((1,2),(3,4),(5,6))

?

Gerhard
-- 
mail:   gerhard <at> bigfoot <dot> de       registered Linux user #64239
web:    http://www.cs.fhm.edu/~ifw00065/    OpenPGP public key id 86AB43C0
public key fingerprint: DEC1 1D02 5743 1159 CD20  A4B6 7B22 6575 86AB 43C0
reduce(lambda x,y:x+y,map(lambda x:chr(ord(x)^42),tuple('zS^BED\nX_FOY\x0b')))




More information about the Python-list mailing list