Find Students in Both Classes
Intermediate · Write the code · from Python Sets: Unique Collections, Operations, and Use Cases
From the lesson: Python Sets: Unique Collections, Operations, and Use Cases
Imagine you're a teacher taking attendance. A student accidentally signs the attendance sheet twice. Does that mean they're in class twice? Of course not. You only care about who showed up, not how many times they wrote their name.
Read the lessonYou have two sets: math and english. Find and print the students who are enrolled in both classes. Print the result as a sorted list.
math = {'Alice', 'Bob', 'Charlie', 'Diana'}
english = {'Bob', 'Diana', 'Eve', 'Frank'}
# Find students in both classes and print sorted
More Sets exercises
- Remove Duplicates from a ListBeginner
- Predict the Set OutputBeginner
- Fix the Empty Set BugIntermediate
- Find Missing IngredientsIntermediate
- Deduplicate While Preserving OrderAdvanced
All Python exercises · 50 practice problems · Data Structures quiz