def get_path(task, graph, child_list=[]):
for child in graph[task]:
if child not in child_list:
child_list.append(child)
get_path(child, graph, child_list=child_list)
return child_list
graph = {"A": ["B"], "B": ["C"], "C": ["D"], "D": []}
print(get_path("A", graph)) #output: ['B', 'C', 'D']. So far so good.
print(get_path("C", graph)) #output: ['B', 'C', 'D']. Strange, we expected ['D'].