← Back to challenges

Count Ones in a 2D Array

PythonHardarraysloops

Instructions

Create a function to count the number of 1s in a 2D list.

Examples

count_ones([
  [1, 0],
  [0, 0]
]) ➞ 1

count_ones([
  [1, 1, 1],
  [0, 0, 1],
  [1, 1, 1]
]) ➞ 7

count_ones([
  [1, 2, 3],
  [0, 2, 1],
  [5, 7, 33]
]) ➞ 2

Notes

N/A

python3
Loading editor…
to run
Walks through the solution with reasoning and edge cases.
Next: Check if String Ending Matches Second String