List transpose method

Paul Winkler slinkp23 at yahoo.com
Thu Nov 1 20:01:31 EST 2001


On Thu, 1 Nov 2001 22:45:05 +0100, Gerhard Häring <gh_pythonlist at gmx.de> wrote:
>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))

Easy questions are answered faster by the python prompt than by
usenet. Hint: Try the most obvious thing that comes to mind.

--PW




More information about the Python-list mailing list