Possible Duplicate:
Matrix Transpose in Python
I have a matrix, say
A = [[0,0],[1,1]]
and I would like to zip its components to have
(0,1),(0,1)
With two rows in A, this can be obtained easily with
zip(A[0],A[1])
What if I have a matrix A of any dimension
A = [[0,0],[1,1],[2,2]]
How to zip a sequence of elements?
Thanks for your ideas.
Use zip(*A)
.
>>> zip(*A)
[(0, 1, 2), (0, 1, 2)]
If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!
Donate Us With