Advanced
Capstone piece: a chunker with overlap
Write chunk_text(text, size, overlap) that splits text into chunks of up to size words, where each chunk starts size - overlap words after the previous one. Return a list of strings (words joined by one space).
Raise ValueError if size <= overlap or if overlap is negative. Blank text gives []. Stop as soon as a chunk reaches the end of the text, so the last chunk is never made only of overlap.
What Check tests
- Chunks overlap
- Short text gives one chunk
- No overlap-only tail
- Blank text
- Bad settings raise ValueError
- Negative overlap raises ValueError
- Zero overlap splits evenly
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.