Command Palette

Search for a command to run...

Hectal
Phase 17: Interviews and Capstone
Python · Exercise 5 of 6 PreviousNext
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

  1. Chunks overlap
  2. Short text gives one chunk
  3. No overlap-only tail
  4. Blank text
  5. Bad settings raise ValueError
  6. Negative overlap raises ValueError
  7. 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.