› 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.

