Is there a path?

graph is an adjacency dictionary for a directed graph: an entry "A": ["B"] means you can go from A to B but not necessarily back. Every node is a key. Write path_exists(graph, start, goal) that returns whether goal can be reached from start by following edges. A node can reach itself.

graph = {"A": ["B"], "B": ["C"], "C": [], "D": ["A"]}
path_exists(graph, "A", "C")  ->  True
path_exists(graph, "C", "A")  ->  False
path_exists(graph, "D", "C")  ->  True

The point is to practise depth-first search with a visited set on a graph that may contain cycles.

def path_exists(graph, start, goal):
    ...