🐸

The Treasure List

The Data Tinkererpython-data-tinkerer-24-the-treasure-list
Reward: 130 XP
|

The Treasure List

Hoppy spreads a few newly found treasure clues across the workbench. The chest label is on one scrap of paper, the keeper's name sits in a corner note, the clue word is pressed under a stone, and the treasure names are scattered off to one side.

If those details stay loose, nobody can understand them at a glance. So today we take one more step: not just reading a structured record, but building one ourselves in a JSON-style shape.

A JSON-style result is usually just dict plus list arranged clearly

When you use a Python dict for named fields and a list for a group of items, the printed result already looks a lot like a JSON record. Today's goal is not file writing. It is learning to organize information into that clear shape.

camp_name = "Moss Shelf"
token_names = ["bell", "rope"]

camp_record = {
  "camp_name": camp_name,
  "tokens": token_names
}

print("Camp record:", camp_record)

Nothing here gets written to a file, and we are not talking about serialization yet. We are simply turning a few loose pieces into one record with named fields and a list inside it. That is the real move for today.

Today's task: gather the scattered treasure details into one clear record

The starter already gives you chest_label, keeper_name, clue_word, and treasure_names. Your job is to organize them into a new treasure_record.

1
Notice which details are still loose

Run the starter and look at how the treasure information is currently spread across separate variables.

2
Build treasure_record with clear fields

Set treasure_record to a dict that uses these keys: "chest_label", "keeper_name", "clue_word", and "treasures".

3
Compare loose values with the structured record

When you run it again, you will see the same information once as loose pieces and once as a tidier record. That is the first step from scattered data toward JSON-style output.

Keep the boundary narrow

Today is only about building a JSON-style result with dict and list. We are not writing to a file, using json.dumps(), or moving into API response formats.

Suggested Solution
Expand
Solution:
chest_label = "Fernlight Chest"
keeper_name = "Mira"
clue_word = "silver fern"
treasure_names = ["amber key", "moon coin", "moss compass"]

print("Loose pieces:")
print("Chest label:", chest_label)
print("Keeper name:", keeper_name)
print("Clue word:", clue_word)
print("Treasure names:", treasure_names)

treasure_record = {
  "chest_label": chest_label,
  "keeper_name": keeper_name,
  "clue_word": clue_word,
  "treasures": treasure_names
}

print("Treasure record:", treasure_record)
Advanced Tips
Want more? Click to expand

The main instinct to keep from today is that structured output does not always come from somewhere else. You can build it yourself. If the field names are clear and the list sits in the right place, the result is already much closer to a record another tool or person could use.

In the next lesson, Hoppy will shift from JSON-shaped records to another common shape: CSV tables organized by rows and columns.

Loading...
Terminal
Terminal
Ready to run...