The Noisy Scroll
Hoppy unrolls a thin scroll on the corner of the detective desk. The clues are not destroyed, but each row carries a little noise: marker prefixes, cramped tildes, and extra question marks that make the real content look messier than it is.
This is exactly what Chapter 5 wants to confirm: when text is not tidy, you do not stop at “this looks messy.” You know how to clean it first, split it open next, and then organize the result clearly.
Noisy text often needs cleanup before parsing
Some text does not need a complex parser. It is only covered by a few small layers of noise. If you apply a short sequence of moves like strip(), replace(), and split(), the original structure starts showing itself again.
sample_line = " ## room=ivy~bridge | clue=glow | status=ready?? "
cleaned_line = sample_line.strip().replace("## ", "").replace("~", " ").replace("??", "")
room_name = cleaned_line.split(" | ")[0].split("=")[1]
print(cleaned_line)
print(room_name)
This example only shows the feeling of “clean one line first, then pull one field from it.” It is not the full answer to today’s starter. In the real task, you will clean a whole small scroll through several connected steps and then gather the results.
Today’s task: turn one noisy scroll into a usable result
The starter already reads noisy_scroll.txt and builds scroll_lines = scroll_text.splitlines(). Your job is to keep going: clean all three scroll rows into first_clean_line, middle_clean_line, last_clean_line, and cleaned_lines, then extract first_room, middle_status, and last_clue, and finally gather them into scroll_report.
Run the starter and inspect scroll_text and scroll_lines. It is not the cleaned result yet, but it already turns the full scroll into separate rows you can work with.
For every row, first call strip(), then remove the leading "## ", then replace "~" with a space, and remove "??". After that, all three rows return to the same clear shape.
Once the cleanup is done, every row looks like room=... | clue=... | status=.... Now use split(" | ") and split("=") to read first_room, middle_status, and last_clue.
Build one dict named scroll_report from cleaned_count, first_room, middle_status, and last_clue. That way you do not only clean the text — you also organize the result clearly.
This lesson is not a large combined project and not the world-trial chapter yet. We are not introducing a new concept and not building a complex parser. We are only confirming that you can naturally chain cleanup, parsing, and result organization together.
Suggested SolutionExpandCollapse
with open("noisy_scroll.txt", "r", encoding="utf-8") as file:
scroll_text = file.read().strip()
print("Scroll text:")
print(scroll_text)
scroll_lines = scroll_text.splitlines()
print("Scroll lines:", scroll_lines)
first_clean_line = scroll_lines[0].strip().replace("## ", "").replace("~", " ").replace("??", "")
middle_clean_line = scroll_lines[1].strip().replace("## ", "").replace("~", " ").replace("??", "")
last_clean_line = scroll_lines[2].strip().replace("## ", "").replace("~", " ").replace("??", "")
cleaned_lines = [first_clean_line, middle_clean_line, last_clean_line]
cleaned_count = len(cleaned_lines)
first_room = cleaned_lines[0].split(" | ")[0].split("=")[1]
middle_status = cleaned_lines[1].split(" | ")[2].split("=")[1]
last_clue = cleaned_lines[2].split(" | ")[1].split("=")[1]
scroll_report = {
"cleaned_count": cleaned_count,
"first_room": first_room,
"middle_status": middle_status,
"last_clue": last_clue,
}
print("First clean line:", first_clean_line)
print("Middle clean line:", middle_clean_line)
print("Last clean line:", last_clean_line)
print("Cleaned lines:", cleaned_lines)
print("Cleaned count:", cleaned_count)
print("First room:", first_room)
print("Middle status:", middle_status)
print("Last clue:", last_clue)
print("Scroll report:", scroll_report)Advanced TipsWant more? Click to expandClick to collapse
The main thing this checkpoint wants to confirm is not how many string method names you remember. It is whether you have a stable path now: clean the noise away, split by the visible shape, and organize the result into clear output.
At this point, Chapter 5 closes its text-detective loop. The next chapter will place these habits inside longer tasks, but it will not depend on winning with new concepts.