List transpose method

Emile van Sebille emile at fenx.com
Thu Nov 1 18:45:17 EST 2001


"Don O'Donnell" <donod at home.com> wrote in message
news:3BE1DD41.C58238FE at home.com...
> 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

Cool.  I hadn't realized that zip could be used for more than two sequences.

--

Emile van Sebille
emile at fenx.com

---------




More information about the Python-list mailing list