Turn the Table Sideways

Python for AIHard+10 XP+10

Turn the Table Sideways

A table is stored as a list of rows. You want it the other way round: a list of columns.

Write flip(grid) that returns a new list of lists where row i of the result is column i of the original.

  • Every row in grid has the same length, and that length is at least 1.
  • An empty grid gives an empty list.

Examples

grid = [[1, 2], [3, 4], [5, 6]]
returns [[1, 3, 5], [2, 4, 6]]
grid = [[1, 2, 3], [4, 5, 6]]
returns [[1, 4], [2, 5], [3, 6]]
grid = []
returns []

Hints

Solve it to unlock the solution

Once your code passes every test, a reference solution shows up here so you can compare it with yours.

solution.py
CtrlEnterto run