UNIT 02 · TOPIC 17
Sets
Sets store unique hashable values and provide efficient membership and set operations.
The idea
Sets, simply explained
Sets store unique hashable values and provide efficient membership and set operations.
01
See the big picture
How the idea flows
Read the diagram as a simple path: begin with a problem, use the Python idea, then verify the result.
02
Everyday connection
Real-life example
↗
An event check-in list uses a set so scanning the same badge twice does not count two guests.
03
Learn by doing
Python code example
PYTHONExample
attendees = {'Riya', 'Aman', 'Riya'}
print(len(attendees), 'Riya' in attendees)Expected result
2 TrueTry it: Change one value in the code, predict what will happen, then run it and compare your answer.
04
Keep this in mind
Key takeaways
- Sets store unique hashable values and provide efficient membership and set operations.
- Think of a real problem where sets could save time or organize information.
- Test small changes and read the result carefully before moving to a bigger program.
Quick self-check
Can you explain it in your own words?
What is the main idea of Sets?
Sets store unique hashable values and provide efficient membership and set operations.
Where could you see this idea in everyday life?
An event check-in list uses a set so scanning the same badge twice does not count two guests.
