Lesson 2 · Dictionaries — Knowledge ChecksAnswer key
In our graph dictionary, what are the keys and what are the values?
Each node is a tuple key, and its value is the list of nodes it connects to — the Python version of the paper graph.
Given graph = {(0,0): [(0,1)]}, what does (0,0) in graph return?
in checks whether a key exists. (0,0) is a key, so it returns True. (Accessing a missing key with [] would raise KeyError — which is why we use in.)
In build_grid_graph, why is each neighbor guarded by an if (like `if row > 0`)?
The bounds checks prevent adding neighbors that fall off the edge of the grid, so corners get 2 neighbors and interior nodes get 4.
To block node (1,1), what two things must happen to the graph dictionary?
Deleting only the key leaves dangling references — neighbors still list (1,1). You must also clean it out of every neighbor list.