Which loop goes outside?
The loop on the outside decides which direction you walk. With rows outside and columns inside, you read the grid like a book: the whole of row 0, then the whole of row 1.
Swap the loops, and you walk down the columns instead: the whole of column 0, then the whole of column 1. That's what you want for a sum of each column. Decide what each pass of the outer loop should finish, then put that loop outside.
Walking by position
To walk down a column you need positions, because you have to say which row and which column. A grid's number of rows is its length. The number of columns is the length of any row, such as the first.
For the sum of each column, loop over the column positions. Inside, start a total, loop over the row positions, and add the cell at that row and that column. When the inner loop is done, that column's sum is ready, so add it to the answer list.
sums = []
for c in range(len(grid[0])):
total = 0
for r in range(len(grid)):
total = total + grid[r][c]
sums.append(total)- sums
- [5]
- column
- 0
Column 0: the inner loop goes down it, adding 1 and 4. The first column's sum is 5.