Intermediate
Chunk words with overlap
Write chunk_words(words, size, overlap) that returns a list of strings, each the joined words (with single spaces) of one window of at most size words. Each window starts size - overlap words after the previous one, and the last window ends at the last word.
If overlap >= size, raise ValueError. An empty list of words gives []. If all words fit in one window, return that one chunk.
What Check tests
- 46 words, size 12, overlap 0 give 4 chunks
- 46 words, size 12, overlap 4 give 6 chunks
- The second chunk starts 8 words after the first
- The last chunk reaches the last word
- Few words give one chunk, and no words give
[] overlap >= sizeraisesValueError
Stuck? One hint at a time
The solution unlocks after your first Check. Try first: that is where the learning happens.
main.py
Sign in to run your code.
Output
Press Run to see what your program prints.