grid = [[(0, 0, 0) for x in range(10)] for x in range(20)]
accepted_pos = [[(j,i) for j in range(10) if grid[i][j] == (0, 0, 0)] for i in range(20)]
accepted_pos = [j for sub in accepted_pos for j in sub]
grid
is stored in the list in 20 bundles of [(0,0,0),(0,0,0),]
10 each.
In the second row, is stored in bundles I don't understand the third line. grid[i][j] to
grid[19][9]
grid[i][9]
grid[i][j]==(0,0,0)
is checked to see if grid[(0,0), (1,0)],
10
[(0,0),(1,0)...]
It seems to make it [(0,0),(1,0)...]
in the multidimensional list, but I don't understand something....
My guess is that initializing the first row - grid to (0, 0, 0) * 10 * 20 is the initial step, and then we'll just use the second and third rows.
Assuming that, the result from line 2 is We find the first row, then the next row, then the next row, and then the column. As you wrote, it falls into a two-dimensional array.
But it's uncomfortable to use it as it is.
For example, there's something to find here, and I think it's because I think it's more convenient to simplify and continue using one-dimensional arrangements like in row 3 than to rotate in two dimensions every time.
© 2024 OneMinuteCode. All rights reserved.