Join us and get access to hundreds of tutorials and a community of expert Pythonistas.

Unlock This Lesson

This lesson is for members only. Join us and get access to hundreds of tutorials and a community of expert Pythonistas.

Unlock This Lesson

Multiple Recursive Calls

In this lesson, you’ll go over the code for the recursive solution to the Santa Claus problem from the first lesson:

def deliver_presents_recursively(houses):
    if len(houses) == 1:
        print("Delivering presents to", houses[0])
    else:
        mid = len(houses) // 2
        first_half = houses[:mid]
        second_half = houses[mid:]

        # first elf
        deliver_presents_recursively(first_half)
        # second elf
        deliver_presents_recursively(second_half)

Comments & Discussion

Become a Member to join the conversation.