I have [[1,2,3], [5,6,7]]
and want to produce the list [[1,5], [2,6], [3,7]]
. How do I do this in Python?
Asked
Active
Viewed 2,297 times
-1

Kijewski
- 25,517
- 12
- 101
- 143

user4127551
- 25
- 4
-
2related: [Matrix Transpose in Python](http://stackoverflow.com/q/4937491/4279) – jfs Oct 17 '14 at 23:52
-
Thank you. the matrix transpose works. – user4127551 Oct 17 '14 at 23:55
2 Answers
0
>>> zip([1,2,3], [4, 5, 6])
[(1, 4), (2, 5), (3, 6)]
To convert each element to a list
>>> [list(a) for a in zip([1, 2, 3], [4, 5, 6])]
[[1, 4], [2, 5], [3, 6]]

Anthony Kong
- 37,791
- 46
- 172
- 304