def generic_bfs_edges(G, source, neighbors=None):
 visited = {source}
 queue = deque([(source, neighbors(source))])
 while queue:
  (parent, children) = queue[0]
  try:
   child = next(children)
   if (child not in visited):
    (yield (parent, child))
    visited.add(child)
    queue.append((child, neighbors(child)))
  except StopIteration:
   queue.popleft()

def generic_bfs_edges ( G , source , neighbors = None ) : visited = { source } queue = deque ( [ ( source , neighbors ( source ) ) ] ) while queue : ( parent , children ) = queue [ 0 ] try : child = next ( children ) if ( child not in visited ) : ( yield ( parent , child ) ) visited . add ( child ) queue . append ( ( child , neighbors ( child ) ) ) except StopIteration : queue . popleft ( )
iterates over edges in a breadth-first search .