🐸

The Shared Shelf

The Data Tinkererpython-data-tinkerer-12-the-shared-shelf
Reward: 110 XP
|

The Shared Shelf

After the membership bell rings, Hoppy finally steps deeper into the record room. Two low wooden shelves wait by the wall: the left shelf holds the scroll titles that were requested for today, and the right shelf holds the scroll titles that have actually arrived. Each shelf is really just a set of names.

Hoppy wants to answer two practical questions first: which scrolls appear on both shelves, and which scrolls are still missing from the arrival shelf even though they were requested? Once you can see the shared items and the one-sided items, a set stops being only storage and starts becoming a comparison tool.

A set can compare itself with another set

In the last lesson, the shape was “is this one name inside the set?” This lesson moves one small step forward: now you have two sets, so you can compare their shared part and the part that only lives on one side.

requested_scrolls = {"Fern Atlas", "Moon Map", "Bell Log"}
arrived_scrolls = {"Moon Map", "Bell Log", "Sun Note"}

print("Requested scrolls:", requested_scrolls)
print("Arrived scrolls:", arrived_scrolls)

shared_scrolls = requested_scrolls.intersection(arrived_scrolls)
missing_scrolls = requested_scrolls.difference(arrived_scrolls)

print("Shared scrolls:", shared_scrolls)
print("Missing scrolls:", missing_scrolls)

Here, intersection() finds the scrolls that both shelves share. difference() finds the scrolls that are in the requested shelf but not in the arrived shelf yet, which makes the missing part visible.

Keep the relationship concrete: shared and missing

You do not need to make sets feel abstract here. It is enough to picture two shelves side by side: first notice what overlaps, then notice what the request shelf still lacks. For beginners, that concrete picture matters more than memorizing terminology.

Notice that the direction of requested_scrolls.difference(arrived_scrolls) matters. We are not asking “what only arrived?” We are asking “what was requested but has still not arrived?” Change the direction, and the answer changes too.

1
Look at the two prepared sets first

The starter already gives you requested_scrolls and arrived_scrolls. You do not need new data here. The point is to read the relationship from the two prepared sets.

2
Compute the shared items, then the missing items

Use requested_scrolls.intersection(arrived_scrolls) to build shared_scrolls. Then use requested_scrolls.difference(arrived_scrolls) to build missing_scrolls.

3
Run it and notice the two comparison results

First you will see the two original shelves, then the Shared scrolls: and Missing scrolls: lines. The main instinct to keep is that once two sets stand side by side, you can directly inspect what they share and what one side is still missing.

Why are there two results in one lesson?

Because these two moves belong to the same tight comparison picture. The shared set answers “what overlaps,” and the missing set answers “what is still absent from the requested side.” Together they make set relationships feel concrete instead of abstract.

Suggested Solution
Expand
Solution:
requested_scrolls = {"Moss Atlas", "Star Ledger", "Bell Map"}
arrived_scrolls = {"Star Ledger", "Bell Map", "Lantern Log"}

print("Requested scrolls:", requested_scrolls)
print("Arrived scrolls:", arrived_scrolls)

shared_scrolls = requested_scrolls.intersection(arrived_scrolls)
missing_scrolls = requested_scrolls.difference(arrived_scrolls)

print("Shared scrolls:", shared_scrolls)
print("Missing scrolls:", missing_scrolls)
Advanced Tips
Want more? Click to expand

You do not need a bigger catalog of set operators yet, and you do not need abstract mathematical language yet either. Just keep one picture in your head: when two member sets are in front of you, you can compare what overlaps and what one side still lacks.

Later, when you meet tasks like “sign-up list vs attendance list,” “requested tags vs arrived tags,” or “needed materials vs prepared materials,” you can remember this shared shelf. A set is not only for membership checks anymore. It can also help you compare relationships.

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