def depth_first_search(gr, s, path):
 if (s in path):
  return False
 path.add(s)
 for each in gr.neighbors(s):
  if (each not in path):
   depth_first_search(gr, each, path)

def depth_first_search ( gr , s , path ) : if ( s in path ) : return False path . add ( s ) for each in gr . neighbors ( s ) : if ( each not in path ) : depth_first_search ( gr , each , path )
depth first search returns a list of nodes "findable" from s .