Problem 167300 · easy · Phase 01 Prerequisites & Setup

Row Totals

lists · nested-lists · sum-by-hand

A spreadsheet is stored as a list of rows, and each row is a list of numbers. Write row_totals(rows) that returns a new list with the sum of each row, in order. An empty row sums to 0.

Examples

Input:  rows = [[1, 2, 3], [4, 5], []]
Output: [6, 9, 0]

Input:  rows = []
Output: []

Constraints

  • 0 <= len(rows) <= 500
  • each row has at most 100 numbers

Goals

  • Loop over a list of lists
  • Sum each inner list into a new result list
Starting Python…