🎙 Free live masterclass · Sun, 29 Nov, 7:00 pm IST · Java Full Stack roadmap Register free →
Skills101
← Quiz: Matrix Traversal: all 13 questions

Quiz: Matrix Traversal · Question 9 of 13

What does this print? (code)

What does this print?

m = [[1, 2, 3], [4, 5, 6]]
t = [[m[r][c] for r in range(len(m))] for c in range(len(m[0]))]
print(t)
  1. A.[[1, 2, 3], [4, 5, 6]]
  2. B.[[1, 4], [2, 5], [3, 6]]
  3. C.[[4, 5, 6], [1, 2, 3]]
  4. D.[[1, 2], [3, 4], [5, 6]]
Answer & explanation

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

Transposing turns each column into a row, so a 2 × 3 matrix becomes 3 × 2.

Can you get the rest right without peeking?

Take the timed Quiz: Matrix Traversal quiz free. Pass it to earn XP and count towards your certificate.

Start the quiz →