For example, given:
G = nx.DiGraph()
G.add_path([0, 1])
G.add_path([0, 2])
G.add_path([0, 3])
G.add_path([1, 11])
G.add_path([1, 12])
G.add_path([2, 21])
G.add_path([2, 22])
G.add_path([3, 31])
G.add_path([3, 32])
I want this:
0, 1, 2, 3, 11, 12, 21, 22, 31, 32
Why does the networkx documentation of bfs_tree
actually uses bfs_edges
in its example? And not bfs_tree
? The key line from the example given in the bfs_tree documentation:
print(list(nx.bfs_edges(G,0)))
Using bfs_edge instead, e.g. via print(list(nx.algorithms.bfs_tree(G, 0).edges()))
seems to result in the same list as returned by the example code but is obviously more complicated. Can I use bfs_tree()
in a simpler way to obtain a list of _nodes_
of a directed graph in BFS order?
Of course, I could iterate the list returned from bfs_tree
or bfs_edges
and only take the second element. But isn't there a simpler way?