defdfs(graph,start_node): visit =list()# Emtpy list stack =list()# Emtpy list stack.append(start_node)while stack:# When one element of stack is inserted node = stack.pop()# The last element of stackif node notin visit: visit.append(node) stack.extend(graph[node])return visitgraph ={'A': ['B'],'B': ['A','B']}print(dfs(graph, 'A'))