predecessor#

predecessor(G, source, target=None, cutoff=None, return_seen=None)[source]#

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

Parameters:
GNetworkX graph
sourcenode label

Starting node for path

targetnode label, optional

Ending node for path. If provided only predecessors between source and target are returned

cutoffinteger, optional

Depth to stop the search. Only paths of length <= cutoff are returned.

Returns:
preddictionary

Dictionary, keyed by node, of predecessors in the shortest path.

Examples

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