def iterative_dfs(graph, start, path=[]):
  '''iterative depth first search from start'''
  q=[start]
  while q:
    v=q.pop(0)
    if v not in path:
      path=path+[v]
      q=graph[v]+q
  return path
iterative depth first search from start
recipes/Python/576723_dfs_and_bfs_graph_traversal/recipe-576723.py