def bfs_successors(G, source):
 parent = source
 children = []
 for (p, c) in bfs_edges(G, source):
  if (p == parent):
   children.append(c)
   continue
  (yield (parent, children))
  children = [c]
  parent = p
 (yield (parent, children))

def bfs_successors ( G , source ) : parent = source children = [ ] for ( p , c ) in bfs_edges ( G , source ) : if ( p == parent ) : children . append ( c ) continue ( yield ( parent , children ) ) children = [ c ] parent = p ( yield ( parent , children ) )
returns an iterator of successors in breadth-first-search from source .