🐸

The Unique Shelf

The Data Tinkererpython-data-tinkerer-10-the-unique-shelf
Reward: 105 XP
|

The Unique Shelf

After fetching the scroll, Hoppy reaches the return-tag table. A pile of glowing shelf tags has been pulled from old shelves, and the same few labels keep appearing again and again.

If Hoppy only wants to know which different tags exist, all that repeated glow becomes noise. The next action is not sorting, and not remembering who came first. It is finding the unique members. That is when set is useful: duplicates are in the way, and uniqueness is what matters.

A set keeps unique members

A set is a structure for keeping distinct members. If the same tag appears three times, that does not make it three different members. When your job is just to keep track of which tags appeared, one copy is enough.

reclaimed_tags = ["A-7", "B-2", "A-7", "C-1"]

print("Returned tags:", reclaimed_tags)

unique_tags = set(reclaimed_tags)

print("Unique shelf tags:", unique_tags)

The list shows the noisy pile exactly as it came back. The set version keeps only the different tags. That is the key feeling of this lesson: you are not arranging a sequence anymore. You are collecting which members exist.

Why order stops being the point here

Lists and tuples are helpful when position matters. This lesson is about a different question. Hoppy is not asking, “Which tag came first?” Hoppy is asking, “Which shelf tags showed up at all?”

That is why the result is a set. A set cares about unique membership, not about storing every repeated appearance in order. The repeated tags are not extra information anymore. They are just repeated noise.

1
Look at the repeated list first

The starter gives you reclaimed_tags as a list with repeats. Keep that line, because you want to compare the noisy pile with the cleaner result.

2
Turn the repeated pile into a set

Replace the placeholder line with a real set(...) call, and save the result in unique_tags.

3
Run it and watch the duplicates disappear

First you will see the repeated list. Then you will see a set with each different tag only once. Do not worry about the order of the set output. The important thing is that the repeats are gone.

This is not a list trick

The important new idea is not just “another bracket style.” It is a new way to think about data. When the real job is “keep which members exist,” a set fits better than a structure that treats every repeated position as important.

Suggested Solution
Expand
Solution:
reclaimed_tags = ["B-12", "A-3", "B-12", "C-9", "A-3"]

print("Returned tags:", reclaimed_tags)

unique_tags = set(reclaimed_tags)

print("Unique shelf tags:", unique_tags)
Advanced Tips
Want more? Click to expand

You do not need membership checks or set relationships yet. For now, keep one picture in mind: a repeated pile comes in, and a set keeps only the distinct members.

That new instinct matters because Python gives you different structures for different goals. Sometimes you care about order. Sometimes you care about fixed positions. And sometimes you only care which things are present at all.

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