We're sorry but this app doesn't work properly without JavaScript enabled. Please enable it to continue.

This lesson's interactive features are locked, please to keep using them

Recursion Practice

In Doc2Doc, we have a search function to find the longest word in a document.

Assignment

Complete the find_longest_word function without a loop. It accepts two string inputs, document and (optionally) longest_word, which is the current longest word and defaults to an empty string.

  1. You can use .split with maxsplit=1 to split a string into a list of [first_word, rest_of_string].

Assume that a "word" means any series of consecutive non-whitespace characters. For example, find_longest_word("How are you?") should return the string "you?".

Review the provided tests in main_test.py to see the expected behavior, including edge cases.