List transpose method

Don O'Donnell donod at home.com
Thu Nov 1 18:39:58 EST 2001


Tom Harris wrote:
> 
> Hi,
> 
> 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.
> 
>>> lst = [(1,2), (3,4), (5,6)]
>>> trn = apply(zip, lst)
>>> trn
[(1, 3, 5), (2, 4, 6)]

Cheers,
Don



More information about the Python-list mailing list