NetworkX

Previous topic

networkx.dijkstra_predecessor_and_distance

Next topic

networkx.floyd_warshall

Quick search

networkx.predecessor

predecessor(G, source, target=None, cutoff=None, return_seen=None)

Returns dictionary of predecessors for the path from source to all nodes in G.

Optional target returns only predecessors between source and target. Cutoff is a limit on the number of hops traversed.

Example for the path graph 0-1-2-3

>>> G=nx.path_graph(4)
>>> print G.nodes()
[0, 1, 2, 3]
>>> nx.predecessor(G,0)
{0: [], 1: [0], 2: [1], 3: [2]}