Intermediate
Clean pages and drop repeated headers
Write clean_lines(page) that takes one page of text and returns its lines as a list: remove control characters (code 0 to 8 and 11 to 31, which keeps tab and newline), collapse runs of spaces and tabs to one space in each line, strip each line and drop lines that are empty.
Write drop_repeated(pages) that takes a list of pages, each a list of lines, and returns the same structure without any line that appears on more than half of the pages (count a line once per page), and without lines that match Page <number> exactly.
What Check tests
- Control characters are removed
- Whitespace is collapsed and empty lines dropped
- A line on most pages is removed
- A line on exactly half the pages stays
- Page numbers are removed by shape
- A line repeated inside one page is not a header
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.