code: def __plain_bfs(adj, source):
          
          seen = set()
          nextlevel = {source}
          while nextlevel:
              thislevel = nextlevel
              nextlevel = set()
              for v in thislevel:
                  if v not in seen:
                      yield v
                      seen.add(v)
                      nextlevel.update(adj[v])
docs: modified NX fast BFS node generator