Transpose a rectangle
Return the transpose of a rectangular matrix as lists. Return [] for [] or rows with zero columns.
matrix = [[1, 2, 3], [4, 5, 6]]
print(list(zip(*matrix)))Reason about the state
Output row j is input column j. Construct new rows rather than aliasing the original matrix; work is proportional to its cells. Before writing code, identify what each variable means after one iteration. Walk through the example and explain why the next transition preserves that meaning. Then check the smallest permitted input and a case with repeated values. A correct answer follows the contract for every input, including the boundary cases in the checks. Keep any input mutation within the stated rules; return a fresh result when the task asks for one.
Your task
Return the transpose of a rectangular matrix as lists. Return [] for [] or rows with zero columns.
The explanation opens here once every check passes.