← Back to challenges

Sum of the Items in a List

PythonHardarrayslanguage_fundamentalsrecursion

Instructions

Create a function that takes a list and returns the sum of all the items in that list.

Examples

sum_list([1, 2, 3]) ➞ 6
# 1 + 2 + 3 = 6

sum_list([1, [2, [1]], 3]) ➞ 7
# 1 + 2 + 1 + 3 = 7

Notes

  • An item in the list can be another list.
  • Try solving it in a recursive approach without using the built-in sum() function.
python3
Loading editor…
to run
Walks through the solution with reasoning and edge cases.