Question 6
Back to Exercise
What is the output of the following Python program?
m = [[1, 2, 3], [4, 5, 6]]
print([[row[i] for row in m] for i in range(3)])
- A [[1, 2, 3], [4, 5, 6]]
- B [[1, 2], [3, 4], [5, 6]]
- C [[1, 4], [2, 5], [3, 6]] Correct
- D [1, 4, 2, 5, 3, 6]
Correct Answer: Option C
For each column index i, the inner comprehension collects row[i] from every row.
Discussion & Comments 0
Share your method, a shortcut, or ask about a step you didn't follow.
No comments yet. Be the first to share your solution!