RisingCoder Full course โ†’
Day 1Day 2Day 3Day 4
๐Ÿ“–
STUDENT NOTES ยท DAY 11 OF 24

The Magic Register ๐Ÿ“–

A list numbers its wagons. A dictionary NAMES them โ€” like the class register: name on the left, marks on the right.

1Keys and values

๐Ÿ
Py: A dictionary stores pairs: key โ†’ value. Ask by NAME, get the answer instantly โ€” no counting wagons.

2Add, update, remove

๐Ÿค–
Bittu: Assigning to a NEW key adds it. Assigning to an OLD key replaces it. I never keep two entries with the same key.

3Bugly's trap: the missing key

๐Ÿž
Bugly: Ask for someone who is not in the registerโ€ฆ hehehe:

The polite fix โ€” .get() with a backup answer:

Register lookup โ€” try a name!

Renu โ†’ 78

register = {"Renu": 78, "Akash": 92, "Priya": 65}

4Looping through the register

๐Ÿฆ‰
Professor Hoot: .items() hands you both halves of each pair. The most useful dict loop there is.

5Quick quiz! ๐Ÿง 

d = {"a": 1}. What does d["z"] do?
๐Ÿ’ก Square brackets on a missing key crash with KeyError. Use d.get("z", "backup") to stay safe.
Which loop gives you keys AND values?
๐Ÿ’ก .items() yields (key, value) pairs โ€” unpack them into two names.

6Your mission ๐Ÿš€

Mission 1: Make a menu dict: {"samosa": 15, "chai": 10, "momo": 40}. Print the price of momos.
Mission 2: Add "dosa": 50, then print the whole menu with a .items() loop like "samosa costs โ‚น15".
Mission 3: Use .get() to ask for "pizza" with the backup answer "not on the menu!".

Day 11 done โ€” registrar of power! ๐Ÿ“–

Next: tuples that never change and sets that hate duplicates.

Go to Day 12: Tuples & Sets โ†’

๐ŸŽฎ Or test yourself in the Python Arcade โ†’