Predict the Set Output
Beginner · Predict the output · 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 lessonWhat does this code print? Think carefully about how sets handle duplicates and what the len() function returns.
data = [1, 2, 2, 3, 3, 3, 4, 4, 4, 4]
unique = set(data)
print(len(unique))Write a print() statement with the exact output.
# What does this code print?
data = [1, 2, 2, 3, 3, 3, 4, 4, 4, 4]
unique = set(data)
print(len(unique))
More Sets exercises
- Remove Duplicates from a ListBeginner
- Find Students in Both ClassesIntermediate
- Fix the Empty Set BugIntermediate
- Find Missing IngredientsIntermediate
- Deduplicate While Preserving OrderAdvanced
All Python exercises · 50 practice problems · Data Structures quiz