Intermediate
Chunk Markdown with heading paths
Write chunk_markdown(markdown) returning a list of (path, text) tuples, one for every heading that has text under it.
A line that starts with one to three # signs and a space is a heading. Its level is the number of # signs. The path joins the headings above it and itself with " > ", for example Guide > Safety: a heading of level 2 replaces everything from level 2 down in the path.
The text of a section is its non-empty lines, stripped, joined by single spaces. Headings with no text under them (before the next heading) give no tuple.
What Check tests
- Sections with text become chunks
- The path includes the parent heading
- Lines of a section are joined with single spaces
- A new heading of the same level replaces the previous one
- A document with no headings gives no chunks
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.