Removing Duplicates with a Set
Run the Removing Duplicates with a Set MicroSim Fullscreen
Edit in the p5.js Editor
About This MicroSim
This simulation shows a list being processed one value at a time. Each value moves toward a set container:
- New values are accepted into the set (green glow)
- Duplicate values bounce away (red glow and message)
After all steps are complete, clicking Convert to List copies the set values into an output list with duplicates removed.
How to Use
- Click Step to process one element at a time.
- Click Auto Play to animate the entire process automatically.
- Click Reset to restart with the current input list.
- Enter your own comma-separated values and click Apply Input.
- After all items are processed, click Convert to List.
Iframe Embed Code
You can add this MicroSim to any web page by adding this to your HTML:
1 2 3 4 | |
Lesson Plan
Grade Level
9-12 (High School Computer Science)
Duration
10-15 minutes
Prerequisites
- Lists (arrays) and element order
- Basic understanding of sets and uniqueness
Activities
- Predict (3 min): Ask students which values they expect to remain after duplicate removal.
- Explore (6 min): Students step through each value and explain why entries are accepted or rejected.
- Apply (4 min): Students test custom input lists and verify output uniqueness.
Assessment
- Student correctly explains why duplicates are rejected by a set.
- Student predicts final unique output before pressing Convert to List.
- Student uses custom input and interprets the resulting output list.
References
- Python Documentation:
settype and uniqueness behavior. - Intro CS data structures texts on lists vs sets.