The Converter
Hoppy finds a very short supply note tucked into the corner of the data cabinet. It is not already arranged like JSON, and it is not laid out in rows and columns like CSV. It is just a few pieces of text chained together on one line.
That is exactly the instinct for today: data work often does not begin with a perfect structure. You first pull fields out of plain text, then organize those fields into a better record, and finally reshape that record into something easy to show.
Conversion is not one giant jump, but a chain of understandable small moves
Going from text to a structured record, then from that record to display text, usually happens in small steps: split, extract, organize. Today we will walk that chain once, but keep it very light.
camp_note = "camp_name=Moss Shelf | guide=Pip"
parts = camp_note.split(" | ")
camp_name = parts[0].split("=")[1]
guide = parts[1].split("=")[1]
camp_record = {
"camp_name": camp_name,
"guide": guide
}
summary = camp_name + " -> " + guide
print("Camp record:", camp_record)
print("Summary:", summary)
This example shows the move chain, not today's exact starter answer. The real thing to notice is that text can be broken into smaller pieces, those pieces can give you named fields, those fields can become a dict, and that dict can then be reshaped into a display line.
Today's task: turn the note text into a record, then into a display line
The starter already reads supply_note.txt and stores the whole line in supply_note. Your next three moves are to extract the fields, build supply_record, and then create summary_line.
The starter already splits supply_note into parts with " | ". Notice what those pieces look like: each one still feels like a tiny key=value chunk.
Split each piece again with "=" and take the value on the right. That will give you item_name, keeper_name, and shelf_name.
Use those three values to build supply_record, then create one summary_line. That connects the whole chain: text -> structured record -> display text.
Today is only about light conversion: extract fields from plain text, build a dict, then make one display line. We are not entering complex parsers, full ETL, or regex-driven workflows.
Suggested SolutionExpandCollapse
with open("supply_note.txt", "r", encoding="utf-8") as file:
supply_note = file.read().strip()
print("Supply note:", supply_note)
parts = supply_note.split(" | ")
item_name = parts[0].split("=")[1]
keeper_name = parts[1].split("=")[1]
shelf_name = parts[2].split("=")[1]
supply_record = {
"item_name": item_name,
"keeper_name": keeper_name,
"shelf_name": shelf_name
}
summary_line = item_name + " -> " + keeper_name + " @ " + shelf_name
print("Supply record:", supply_record)
print("Summary line:", summary_line)Advanced TipsWant more? Click to expandClick to collapse
The main feeling to keep from this lesson is that conversion is not a magical leap. It is a string of small actions you can actually follow: split the text, pull out the fields, arrange them into structure, then express them again in the form you need.
In the next lesson, Chapter 4 will bring its formats together for one light checkpoint: can you tell which format fits which kind of information?