Project: Contact Book
A contact book is a natural fit for dictionaries: each contact has a name (the key) and a small record of details (the value). You will build one that stores contacts, adds a new one, and prints them in order.
What You'll Build
- Contacts dictname -> details
- Add a contact
- List, sortedloop
Step 1: A Dictionary of Records
Each contact's value is itself a small dictionary. This nesting keeps related details together:
Loading Python Playground...
Step 2: Add a Contact
Adding is just assigning a new key:
Loading Python Playground...
Step 3: List Them in Order
sorted(contacts) gives the names alphabetically. Loop over them and pull each phone number out of the record.
Build It Yourself
Reproduce the exact output below.
Loading Python Exercise...
Make It Your Own
Look up a single contact safely with get() so a missing name does not crash your program:
Loading Python Playground...
Challenge Ideas
- Add a delete feature with
del contacts[name] - Search for contacts whose name starts with a given letter
- Print the email as well as the phone for each contact
Key Takeaways
- Model records as a dictionary of dictionaries
- Add a contact by assigning a new key
sorted(dict)iterates keys in orderget()looks up a contact without risking an error- This is the core of any address book or CRM

