Editor

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 lesson

You 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

All Python exercises · 50 practice problems · Data Structures quiz