← 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)
- A.[[1, 2, 3], [4, 5, 6]]
- B.[[1, 4], [2, 5], [3, 6]]
- C.[[4, 5, 6], [1, 2, 3]]
- 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 →