Counting words
Input
len(Sentence("Hello world"))
Output
2
The sentence contains two words: 'Hello' and 'world'.
Full lesson preview
Make a Sentence class compatible with Python's len() by implementing __len__.
Problem statement
Task
Examples
Input
len(Sentence("Hello world"))
Output
2
The sentence contains two words: 'Hello' and 'world'.
Input format
Output format
Constraints
Samples
Input
len(Sentence(" leading and multiple spaces "))
Output
4
split() ignores extra whitespace and counts 4 words.