[3 - i for i in range(3)]
i = 0 → 3 - 0 = 3
i = 1 → 3 - 1 = 2
i = 2 → 3 - 2 = 1
So the inner list is [3, 2, 1]
[[3 - i for i in range(3)] for j in range(3)]
The outer comprehension repeats the inner list 3 times
my_list = [
[3, 2, 1],
[3, 2, 1],
[3, 2, 1]
]
for i in range(3):
result += my_list[i][i]
i = 0 → my_list[0][0] = 3 → result = 3
i = 1 → my_list[1][1] = 2 → result = 5
i = 2 → my_list[2][2] = 1 → result = 6
A. 6
A voting comment increases the vote count for the chosen answer by one.
Upvoting a comment with a selected answer will also increase the vote count towards that answer by one.
So if you see a comment that you already agree with, you can upvote it instead of posting a new comment.
4ba36e7
1 month, 3 weeks ago