› Forums › Python › From Dictionary of Lists to Dictionary of Objects: Phone Book Explained (Python MOOC 2025)
- This topic is empty.
-
AuthorPosts
-
February 4, 2026 at 5:57 am #5991
🔹 Initial Context
In the Python Programming MOOC 2025, Part 10 covers building larger applications with object-oriented design — including the Phone Book project.
In earlier parts, we stored phone numbers like this:
all_persons = {} # Example: all_persons["Eric"] = ["02-123456", "045-4356713"] all_persons["Emily"] = ["040-324344"]This is a dictionary of lists.
The MOOC course now asks you to change this so that the dictionary stores objects instead of lists — a key step in object-oriented programming.
👉 View the official MOOC page here:
📄 Phone Book with Objects in a Dictionary
https://programming-25.mooc.fi/part-10/4-application-development/ (programming-25.mooc.fi)And here’s the main Part 10 overview:
📄 Developing a larger application (Part 10)
https://programming-25.mooc.fi/part-10/ (programming-25.mooc.fi)
❓ Q1: What’s the limitation of using a dictionary of lists?
Answer:
A dictionary of lists only stores raw data. That becomes hard to manage when new features (like addresses) are needed. It mixes data with logic and does not support encapsulation.
❓ Q2: What does “objects in a dictionary” mean?
Answer:
Instead of:name → list of numbersYou have:
name → Person objectAnd the
Personobject holds all the data and the methods to manage it:👉 Official reference in MOOC:
https://programming-25.mooc.fi/part-10/4-application-development/ (programming-25.mooc.fi)
❓ Q3: What is the
Personclass?Answer:
It encapsulates name, phone numbers, and address:class Person: def __init__(self, name: str): self.__name = name self.__numbers = [] self.__address = None def name(self): return self.__name def numbers(self): return self.__numbers def address(self): return self.__address def add_number(self, number: str): self.__numbers.append(number) def add_address(self, address: str): self.__address = address
❓ Q4: How does the phone book dictionary change?
Answer:
Instead of storing lists:all_persons["Eric"] = ["02-123456"]You store objects:
all_persons["Eric"] = Person("Eric") all_persons["Eric"].add_number("02-123456")
❓ Q5: How does the
PhoneBookclass update?Answer:
It now creates and managesPersonobjects:class PhoneBook: def __init__(self): self.__persons = {} def add_number(self, name, number): if name not in self.__persons: self.__persons[name] = Person(name) self.__persons[name].add_number(number) def add_address(self, name, address): if name not in self.__persons: self.__persons[name] = Person(name) self.__persons[name].add_address(address) def get_entry(self, name): return self.__persons.get(name)
❓ Q6: Why does the UI hardly change?
Answer:
Because the UI calls methods (add_number,add_address,get_entry) that haven’t changed — only the internal data structure has. This follows the separation of concerns principle.Official MOOC guidance on separation of concerns:
https://programming-25.mooc.fi/part-10/4-application-development/ (programming-25.mooc.fi)
❓ Q7: How does searching work now?
Answer:
Instead of returning a list, the UI retrieves aPersonobject:person = phonebook.get_entry(name) if person is None: print("number unknown") else: for number in person.numbers(): print(number)
❓ Q8: Why should you take baby steps in refactoring?
Answer:
Because structural changes affect many places. The course recommends testing each step after making a change to prevent hard-to-find bugs.MOOC reference:
https://programming-25.mooc.fi/part-10/4-application-development/ (programming-25.mooc.fi)
❓ Q9: How is this similar to the
ExerciseCounterexample?Answer:
Both store objects in a dictionary instead of raw data:students[name] = ExerciseCounter() students[name].done()This pattern is exactly what the phone book exercise teaches — replace “list of simple data” with “object with behavior”.
📌 Final Takeaway
✔ Objects help manage growing complexity
✔ A dictionary can hold objects, not just lists
✔ Separation of concerns improves maintainability
✔ Refactor step-by-step to avoid bugs
🔗 Useful MOOC URLs
📄 Phone Book with Objects — MOOC 2025 (Part 10.4)
https://programming-25.mooc.fi/part-10/4-application-development/ (programming-25.mooc.fi)📄 Part 10 Overview — Python MOOC 2025
https://programming-25.mooc.fi/part-10/ (programming-25.mooc.fi)
-
AuthorPosts
- You must be logged in to reply to this topic.

