I have a list
a = [[1,2],[3,4],[5,6],[7,8],[9,10]]
Result
New_a = [[1,3,5,7,9],[2,4,6,8,10]]
Any smart way or python built-in function can solve the problem?
list(zip(*a))
Out[6]: [(1, 3, 5, 7, 9), (2, 4, 6, 8, 10)]
Explanation: zip takes two or more iterables and stitches them together where "the i-th element comes from the i-th iterable argument." The star operator unpacks a so that you zip the elements together, not the sublists.
list?zip returns a generator object. You can drop the list in python2.import numpy as np
a = np.array([[1,2],[3,4],[5,6],[7,8],[9,10]])
Result:
>>> a
array([[ 1, 2],
[ 3, 4],
[ 5, 6],
[ 7, 8],
[ 9, 10]])
>>> a.T
array([[ 1, 3, 5, 7, 9],
[ 2, 4, 6, 8, 10]])