ProgrammingModerateTCS NQT · Accenture

What is printed?

What is printed?
m = [[1, 2, 3], [4, 5, 6]]
rot = [list(r) for r in zip(*m[::-1])]
print(rot)
  1. A. [[1, 4], [2, 5], [3, 6]]
  2. B. [[4, 1], [5, 2], [6, 3]]
  3. C. [[6, 3], [5, 2], [4, 1]]
  4. D. [[3, 6], [2, 5], [1, 4]]

Correct answer: B. [[4, 1], [5, 2], [6, 3]]

Reversing the rows and then transposing with zip rotates the matrix 90 degrees clockwise. The first new row is the first column read from bottom to top.

More Python Programming questions

Exams that ask this topic