0

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?

Ammar Sarif
  • 35
  • 1
  • 8

1 Answers1

0
data = [[1, 2],
        [3, 4],
        [5, 6],
        [7, 8]]

print([*map(list, zip(*data))])

Prints:

[[1, 3, 5, 7], [2, 4, 6, 8]]
Andrej Kesely
  • 118,151
  • 13
  • 38
  • 75