Hackbright Code Challenges

Sum List Recursively

Sum List Recursively

Whiteboard

Medium

Challenge

Easier

Concepts

Recursion, Lists

Download

sum-list-recursively.zip

Solution

Sum List Recursively: Solution


Sum a list of integers using recursion.

For example::

    >>> sum_list([5, 5])
    10

    >>> sum_list([-5, 10, 4])
    9

    >>> sum_list([20])
    20

The sum of an empty list is zero::

    >>> sum_list([])
    0

We’ve given you sum.py, which includes the stub of a sum_list function:

sum.py
def sum_list(nums):
    """Using recursion, return the sum of numbers in a list."""