

0 / 2 embers
0 / 3000 xp
click for more info
Complete a lesson to start your streak
click for more info
Still calibrating
click for more info
Not enough gems
Cost: 6 gems
1: Welcome to Functional Programming
incomplete
2: Why Python?
incomplete
3: Immutability
incomplete
4: Declarative Programming
incomplete
5: It's Math
incomplete
6: Classes vs. Functions
incomplete
7: Debugging FP
incomplete
8: Functional vs. OOP
incomplete
9: Statements vs. Expressions
incomplete
10: Ternary Expressions
incomplete
11: Functions Practice
incomplete
Back
ctrl+,
Next
ctrl+.
This lesson's interactive features are locked, please to keep using them
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.
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.
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