...

Chapter 18 - Python Quest

Graph Map Adventures

Follow one-way missions, detect loops, order dependencies, and grow low-cost weighted networks.

XP
0Level 1
Stars
0/30quest stars
Combo
0clean runs
Rank
Seed0/160 Python score
Reading direct graph neighbors

Map Neighbor Board

100 XP

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"]
graph
HubHubArcadeArcadeLakeLakeStageStageDockDock

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"]
graph
HubHubArcadeArcadeLakeLakeStageStageDockDock

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

Loading editor

Judge

Ready

0/5

Run your code when it feels ready.