Skip to content Skip to sidebar Skip to footer

Convert Output From Dictionary To List With Bfs And Dfs Networkx

I am currently using networkx library for Python with BFS and DFS. I need to get a tree and then explore it to get a path from a start node to an end node. For the BFS part I am us

Solution 1:

IIUC you're not really interested in finding all successors encourtered with nx.bfs_successors, since you only need the path between a source and a target nodes.

For that you can either find the shortest path (in the case there are multiple):

nx.shortest_path(G, source, target)

Or find all simple paths between them:

nx.all_simple_paths(G, source, target)

Which returns a generator with all simple paths between both nodes.

Post a Comment for "Convert Output From Dictionary To List With Bfs And Dfs Networkx"