๐
STUDENT NOTES ยท DAY 12 OF 24
Locked Boxes & the No-Repeats Club ๐
Two special containers: the tuple (a list that can NEVER change) and the set (a club that refuses duplicates).
1Tuples โ sealed at birth
๐
Py: Round brackets make a tuple. Read it, loop it, index it โ but change it? Never. Perfect for things that must stay fixed, like GPS coordinates.
๐
Bugly: Try to edit oneโฆ hehehe:
2The one-item tuple trap
๐ฆ
Professor Hoot: (5) is just the number 5 wearing brackets. The COMMA makes the tuple: (5,). Tiny comma, big difference.
3Sets โ the no-duplicates club
๐ค
Bittu: I check membership in a set at lightning speed โ in is my favourite word.
4Set tricks
5Quick quiz! ๐ง
t = (1, 2, 3); t[0] = 9 โ what happens?
๐ก Tuples are immutable. Once made, forever sealed.
What is len({1, 2, 2, 3, 3, 3})?
๐ก The set bounces duplicates at the door: only {1, 2, 3} get in.
6Your mission ๐
Mission 1: Store your birthday as a tuple (day, month, year). Try changing it โ read the error like a pro.
Mission 2: Make a set from the list [1,2,2,3,3,3,4] and print how many UNIQUE numbers there are.
Mission 3: Use set("your own name") to find your unique letters!
Day 12 done โ halfway through the course! ๐
Next: files โ teach your programs to REMEMBER after they close.
Go to Day 13: Files โ