Hackbright Code Challenges

Count List Recursively: Solution

Count List Recursively: Solution

Problem

Count List Recursively

Whiteboard

Medium

Challenge

Easier

Concepts

Recursion

Download

count-recursively-solution.zip


def count_recursively(lst):
    """Return number of items in a list, using recursion."""

    # START SOLUTION

    if not lst:
        return 0

    return 1 + count_recursively(lst[1:])