› Forums › Python › CS50’s Introduction to Artificial Intelligence with Python › Does the CS50 Degrees Project Use 4 Dictionaries? Understanding Main vs Nested Dictionaries in Python
- This topic is empty.
-
AuthorPosts
-
April 22, 2026 at 4:13 am #6441
https://cs50.harvard.edu/ai/projects/0/degrees/
Many learners studying the Degrees of Separation project from :contentReference[oaicite:0]{index=0} ask an excellent question:
“If I see dictionaries inside dictionaries, does that mean there are 4 dictionaries in the program?”
The short answer is: No. There are 3 main dictionaries, while some values inside them are nested dictionaries.
The 3 Main Dictionaries in the Program
At the top level, the program stores data in these three dictionary variables:
names = {} people = {} movies = {}These are the core data structures loaded from CSV files.
1. The
namesDictionarynames["tom hanks"] = {"158"}This maps a person’s lowercase name to one or more IDs.
- Name = key
- Set of IDs = value
2. The
peopleDictionarypeople["158"] = { "name": "Tom Hanks", "birth": "1956", "movies": {"12", "37"} }This maps a person ID to another dictionary containing that person’s details.
Important: The inner part is a nested dictionary.
3. The
moviesDictionarymovies["12"] = { "title": "Forrest Gump", "year": "1994", "stars": {"158", "991"} }This maps a movie ID to another dictionary containing movie details.
Why It Looks Like More Than 3 Dictionaries
Because these lines are true:
type(people) # dict type(people["158"]) # dictSo yes, a dictionary exists inside another dictionary. But that inner dictionary is a value, not a separate top-level program variable.
Best Analogy: Cupboards and Folders
Imagine your program has 3 cupboards:
- names cupboard
- people cupboard
- movies cupboard
Inside the people cupboard, each folder contains more organized sheets.
Still only 3 cupboards.
Why This Matters in Real Programming
Understanding nested dictionaries helps with:
- JSON APIs
- Flask and Django apps
- Configuration files
- Database-like Python structures
- Graph problems like CS50 Degrees
Final Answer
The program uses 3 main dictionaries. Some entries inside those dictionaries are themselves dictionaries, called nested dictionaries.
Learning Tip: When you see a dictionary inside another dictionary, ask:
Is this a new variable? Or just a value stored inside another structure?That question will sharpen your Python thinking quickly.
-
AuthorPosts
- You must be logged in to reply to this topic.
