🐸

The Fixed Pair

The Data Tinkererpython-data-tinkerer-08-the-fixed-pair
Reward: 105 XP
|

The Fixed Pair

With the badge ready, Hoppy steps into the forest archive. The keeper hands over a moon-map scroll and says this record needs two pieces saved together: the scroll name and its shelf code.

If those pieces stay loose, you can still read them, but they are meant to travel as one record. Hoppy needs a small archive card that fixes the pair in one place. This new chapter starts here because you are not only polishing text anymore; you are learning to store information by structure.

First, feel the change from loose pieces to one record card

The main thing to notice is very small but very important: two separate values can become one fixed pair. Here, the first slot means the scroll name, and the second slot means the shelf code.

record_name = "Fern Ledger"
shelf_code = "A-7"

print("Loose name:", record_name)
print("Loose shelf:", shelf_code)

scroll_record = (record_name, shelf_code)

print("Record card:", scroll_record)

When you run this, the first two lines still look like separate bits of information. The last line looks different: scroll_record is one tuple, shown with parentheses. That shape helps you see that the name and shelf code now travel as one small record.

Tuple means a fixed little structure

A tuple is useful when a few values naturally belong together and their positions matter. In this record card, the order is part of the meaning: first the scroll name, then the shelf code.

This is why tuple feels more natural than list here. A list feels like a row of items you may keep adding to or rearranging. A tuple feels more like a ready-made card with fixed slots. Hoppy is not making a checklist here. Hoppy is saving one bound pair.

1
Find the placeholder line for the record card

The starter already shows the loose name, the loose shelf code, and the final print line. The real work is on the scroll_record line.

2
Build one tuple from the two existing values

Write a tuple with parentheses, and put record_name first and shelf_code second.

3
Run it and compare loose pieces with the fixed pair

First you will see the two separate lines. Then you will see the tuple on the Record card: line. The key change to notice is: two loose values became one stored pair.

Why not use a list here?

Because this is not a pile of separate items. It is one small record with two fixed slots. The first slot means name, and the second slot means shelf code. That fixed shape is exactly the feeling you want to build for tuples.

Suggested Solution
Expand
Solution:
record_name = "Moon Map"
shelf_code = "B-12"

print("Loose name:", record_name)
print("Loose shelf:", shelf_code)

scroll_record = (record_name, shelf_code)

print("Record card:", scroll_record)
Advanced Tips
Want more? Click to expand

Programmers use tuples when the shape is already decided and the values belong together. You do not need bigger tuple rules yet. The important new instinct is simpler: some data is not just a loose list of things — it is one fixed little record.

In this chapter, that matters because you are starting to think about where information lives. For now, just get comfortable creating the pair and recognizing why it makes sense as one structure.

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