+ 1

How does it work ?

f = 1 A = [[1, 2, 3], [2, 3, 4], [3, 4, 5]] for i in range(0, 3): f =f*i for j in range(0, 3): A[i][j] = f print(A)

5th Feb 2019, 10:30 AM
Iskandar Nabiev
Iskandar Nabiev - avatar
3 Answers
+ 1
You can index arrays by [], each position is numbered from 0 to length-1. If you store arrays in arrays, you can do it for the inner lists too. So A[0][2] is 3 (first element of outer array, and there the third element). The embedded for loops create the indexes for the 2d array: two numbers i and j from 0 to 2. And then A[i][j] will be changed to what f is now. You only have to play this out in your mind or on paper step by step. The interesting point is line 4. Let's do this for i == 0: f = 1*0 -> f == 0, right? So from now on, whatever i will be, f will remain 0 (0*1, 0*2). And if f is always 0, then every spot of the array will be set to 0 in line 6.
5th Feb 2019, 1:05 PM
HonFu
HonFu - avatar
+ 1
the answer is likely to be?
5th Feb 2019, 1:15 PM
Iskandar Nabiev
Iskandar Nabiev - avatar
0
Have you read my post?
5th Feb 2019, 1:30 PM
HonFu
HonFu - avatar