Let's say that:
>>> data
[[1, 2],
[3, 4],
[5, 6],
[7, 8]]
When rows and columns are swapped:
>>> data
[[1, 3, 5, 7],
[2, 4, 6, 8]]
How do I achieve the following without the use of external libraries such as pandas or numpy?
Let's say that:
>>> data
[[1, 2],
[3, 4],
[5, 6],
[7, 8]]
When rows and columns are swapped:
>>> data
[[1, 3, 5, 7],
[2, 4, 6, 8]]
How do I achieve the following without the use of external libraries such as pandas or numpy?
data = [[1, 2],
[3, 4],
[5, 6],
[7, 8]]
print([*map(list, zip(*data))])
Prints:
[[1, 3, 5, 7], [2, 4, 6, 8]]