What will be the output of the following Python code? [code]l=[[1 ,2, 3], [4, 5, 6], [7, 8, 9]] [[row[i] for row in l] for i in range(3)][/code]

Julipkq

New member
What will be the output of the following Python code?
Code:
l=[[1 ,2, 3], [4, 5, 6], [7, 8, 9]]
[[row[i] for row in l] for i in range(3)]
A. Error
B. [[1, 4, 7], [2, 5, 8], [3, 6, 9]]
C.
1 4 7
2 5 8
3 6 9
D.
(1 4 7)
(2 5 8)
(3 6 9)
 
Answer: b
Explanation: In the code shown above, ‘3’ is the index of the list. Had we used a number greater than 3, it would result in an error. The output of this code is: [[1, 4, 7], [2, 5, 8], [3, 6, 9]].
 

Tìm kiếm

Back
Top