Transpose a Grade Matrix

Hard ⏱ 18 min 39% acceptance ★★★★★ 4.9
Grades are stored per-student as rows; analysts want them per-subject as columns. Write transpose(matrix) for a rectangular list-of-lists using nested comprehensions only — no zip.

Examples

Example 1
Input
transpose([[1, 2, 3], [4, 5, 6]])
Output
[[1, 4], [2, 5], [3, 6]]
Explanation

Rows become columns.

Constraints

  • No zip, no numpy.
  • Assume a non-empty rectangular matrix.

Topics

List Comprehensionsnested comprehension

Companies

GoogleMicrosoft

Hints

Hint 1

The outer comprehension iterates over column indices.

Hint 2

[[row[i] for row in matrix] for i in range(len(matrix[0]))].

Loading the Python runtime… Run executes your code and shows printed output; Submit checks your function against this problem's examples.