What is the slickest way to transpose a square list of lists (tuple of tuples)?
Tim Hochberg
tim.hochberg at ieee.org
Sun Jan 8 16:39:31 EST 2006
Brian van den Broek wrote:
> Gerard Brunick said unto the world upon 08/01/06 01:27 PM:
>
>>My way is ugly. These has to be a better way.
>>
>>Thanks,
>>Gerard
>
>
> If you'd posted your way, I might well have seen if I could do it in a
> nicer fashion. But, since for all I know, my best efforts would result
> in the approach you already have, I'm unlikely to put the effort in.
>
> I suspect I'm not alone. You might do well to show the approach you
> are unhappy with.
Indeed. And it would also make it obvious what you're trying to do as
I'm not completely convinced I understand your description. However, if
my guess is correct:
transposed = zip(*listoflists)
is probably hard to beat.
-tim
More information about the Python-list
mailing list