Hackbright Code Challenges

Sum List Recursively: Solution

Sum List Recursively: Solution

Problem

Sum List Recursively

Whiteboard

Medium

Challenge

Easier

Concepts

Recursion, Lists

Download

sum-list-recursively-solution.zip


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

    # START SOLUTION

    if not nums:
        return 0

    return nums[0] + sum_list(nums[1:])