Graphs · routine
Who can I reach?
A graph is a dictionary from each place to a list of its neighbours: {"a": ["b"], "b": ["c"], "c": []}.
Write reachable(graph, start) returning a list (any order) of every place you can get to from start, including start itself. Graphs can have loops — do not walk forever.
- right answers
- arguments left as they should be
Run adds print(reachable({"a": ["b"], "b": ["c"], "c": []}, "a")) after your code, to try it.
Stuck on the idea rather than the code? The Graphs lesson walks through it.