🐸

The Membership Bell

The Data Tinkererpython-data-tinkerer-11-the-membership-bell
Reward: 105 XP
|

The Membership Bell

After Hoppy sorts the returned shelf tags, a small copper bell glows deeper inside the forest archive. Beside it is not a long sign-in sheet, but a magic member list with "Pip", "Mora", and "Tala" glowing on it.

Now "Pip" arrives at the door. Hoppy does not need to count the names or care about their order. The bell asks one direct question: is this name a member of the list? If yes, the visitor may ring; if not, the door should stay quiet.

A set is great for answering “is it in here?”

When the job becomes “is this thing one of the members,” a set feels very natural. A set already focuses on membership, not position. With in, you can ask the question directly and get a boolean answer: True if it belongs, False if it does not.

bell_members = {"Mira", "Jun", "Pip"}
visitor_name = "Jun"

print("Bell members:", bell_members)
print("Visitor:", visitor_name)

can_ring_bell = visitor_name in bell_members

print("Can ring bell:", can_ring_bell)

Here, visitor_name in bell_members reads like a direct question: “Is visitor_name inside bell_members?” This is exactly where a set becomes concrete. You are not counting, and you are not comparing shared items yet. You only want to know whether one target belongs to the list.

This is a lightweight whitelist task

Many real small tasks look like this: whether a tag is allowed through, whether a room is on the safe list, whether a visitor name belongs to the member list. The shape is the same every time: prepare one allowed set, then check whether the target value is inside it.

For this lesson, that one move is enough: one set, one in check, one boolean result. Lock that picture in place first. The next lesson can deal with relationships between sets.

1
Look at the prepared member list and visitor name

The starter already gives you bell_members and visitor_name. You do not need a new set here. The point is to use the one you already have.

2
Replace the placeholder with a real membership check

Use visitor_name in bell_members, and save the result in can_ring_bell.

3
Run it and notice the boolean result

First you will see the member set and the visitor name, then the Can ring bell: line. The main instinct here is that a set is not only for removing repeats. It is also a very natural home for membership checks.

Make the purpose of a set feel concrete

In the last lesson, the set felt like a unique shelf. In this lesson, it becomes a working list. As soon as your question is “does this belong,” set + in starts to feel obvious.

Suggested Solution
Expand
Solution:
bell_members = {"Pip", "Mora", "Tala"}
visitor_name = "Pip"

print("Bell members:", bell_members)
print("Visitor:", visitor_name)

can_ring_bell = visitor_name in bell_members

print("Can ring bell:", can_ring_bell)
Advanced Tips
Want more? Click to expand

You do not need performance theory yet, and you do not need intersections or differences yet either. Just keep one useful picture in your head: you have a set of members, you have one value to check, and in gives you the answer right away.

Later, when you meet whitelists, allow-lists, block-lists, or “already registered” tags, you can remember this membership bell. The real question underneath is often just: “Is it in there?”

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