Chapter 18 - Python Quest
Graph Map Adventures
Follow one-way missions, detect loops, order dependencies, and grow low-cost weighted networks.
Map Neighbor Board
A city kiosk shows every place connected by one direct path. Visitors want nearby choices, not destinations that require another stop.
Write direct_neighbors(graph, place) so it returns place's direct neighbors in the same order as its adjacency list. Return [] when place is not a vertex or has no neighbors. The graph is an undirected adjacency dictionary: each key is a place and its value is a list of connected places.
Sample checks
direct_neighbors(graph, place="Hub")returns["Arcade","Lake"]Explanation: Hub has exactly two incident paths, one to Arcade and one to Lake, and their adjacency-list order is preserved in the returned list
direct_neighbors(graph, place="Lake")returns["Hub","Stage","Dock"]Explanation: Lake touches three direct edges leading to Hub, Stage, and Dock; Arcade is reachable later but is not one edge away from Lake
Hint
Hints are ready when you want one.
Lesson reference
Review: Read one vertex's adjacency list
Your Python
direct_neighbors
Judge
Ready
Run your code when it feels ready.
