Column totals
Inputs
cells is a grid: a list of 1 to 5 rows, each with the same number (1 to 5) of whole numbers from -9 to 9.
Your tasks
- Create a list
totalswith one 0 for each column. - Use nested loops over rows and columns. Add each number to the total for its column.
- Complete
columnTotalsso it returnstotals. Return it, do not print it.
Example
With cells = [[1, 2, 3], [4, 5, 6]], columnTotals returns [5, 7, 9].
Rules
- One total per column, left to right.
Test data
TEST DATA 1: cells is [[1, 2, 3], [4, 5, 6]]
TEST DATA 2: cells is [[7]]
Practice focus
Two-dimensional data is a loop over rows with a loop over columns inside. Grids lead straight to flood fill, islands, dynamic programming tables and path problems.