def breadth_first_search(node, visit=(lambda node: False), traversable=(lambda node, edge: True)):
 q = [node]
 _visited = {}
 while q:
  node = q.pop(0)
  if (not (node.id in _visited)):
   if visit(node):
    return True
   q.extend((n for n in node.links if (traversable(node, node.links.edge(n)) is not False)))
   _visited[node.id] = True
 return False

def breadth_first_search ( node , visit = ( lambda node : False ) , traversable = ( lambda node , edge : True ) ) : q = [ node ] _visited = { } while q : node = q . pop ( 0 ) if ( not ( node . id in _visited ) ) : if visit ( node ) : return True q . extend ( ( n for n in node . links if ( traversable ( node , node . links . edge ( n ) ) is not False ) ) ) _visited [ node . id ] = True return False
visits all the nodes connected to the given root node .