NetworkX

Previous topic

networkx.average_shortest_path_length

Next topic

networkx.shortest_path_length

networkx.shortest_path

shortest_path(G, source, target)

Return a list of nodes in a shortest path between source and target.

There may be more than one shortest path. This returns only one.

Parameters:

G : NetworkX graph

source : node label

starting node for path

target : node label

ending node for path

Examples

>>> G=nx.path_graph(5)
>>> print nx.shortest_path(G,0,4)
[0, 1, 2, 3, 4]