graph = {} def dfs(graph, node, visited): if node not in visited: visited.append(node) for n in graph[node]: dfs(graph,n, visited)