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

Why Python?

Frankly, Python is not the most "functional" programming language. It doesn't enforce static typing, immutability, or pure functions, and it lacks tail call optimization.

So why use it? Well, one reason trumps all others: you already know Python. You can focus on functional concepts without learning a new language at the same time.

Assignment

Doc2Doc's count_words function has a bug! It returns the number of characters in a document instead of the number of words.

Fix count_words by calling .split() on the document and passing its result to len.

Tip

Here's how the .split() method works:

sentence = "this sentence has five words"
words = sentence.split()
print(words)
# ['this', 'sentence', 'has', 'five', 'words']
print(len(words))
# 5