summaryrefslogtreecommitdiff
path: root/networkx/algorithms
diff options
context:
space:
mode:
authorSultan Orazbayev <contact@econpoint.com>2022-07-26 00:31:37 +0600
committerGitHub <noreply@github.com>2022-07-25 14:31:37 -0400
commite32fd8b0ea027aa81c486e674394827402dd94c2 (patch)
tree90863e2f663f2954968883eb39e4e173feea4e3e /networkx/algorithms
parent98060487ad192918cfc2415fc0b5c309ff2d3565 (diff)
downloadnetworkx-e32fd8b0ea027aa81c486e674394827402dd94c2.tar.gz
Update docs to include description of the `return_seen` kwarg (#5891)
* Update docs to include description of the `return_seen` kwarg Update docs to include description of the `return_seen` kwarg (previously not documented) * Run black on the file * Update unweighted.py
Diffstat (limited to 'networkx/algorithms')
-rw-r--r--networkx/algorithms/shortest_paths/unweighted.py17
1 files changed, 15 insertions, 2 deletions
diff --git a/networkx/algorithms/shortest_paths/unweighted.py b/networkx/algorithms/shortest_paths/unweighted.py
index 5363b24d..9d1dff5b 100644
--- a/networkx/algorithms/shortest_paths/unweighted.py
+++ b/networkx/algorithms/shortest_paths/unweighted.py
@@ -460,8 +460,7 @@ def all_pairs_shortest_path(G, cutoff=None):
def predecessor(G, source, target=None, cutoff=None, return_seen=None):
- """Returns dict of predecessors for the path from source to all nodes in G
-
+ """Returns dict of predecessors for the path from source to all nodes in G.
Parameters
----------
@@ -477,12 +476,23 @@ def predecessor(G, source, target=None, cutoff=None, return_seen=None):
cutoff : integer, optional
Depth to stop the search. Only paths of length <= cutoff are returned.
+ return_seen : bool, optional (default=None)
+ Whether to return a dictionary, keyed by node, of the level (number of
+ hops) to reach the node (as seen during breadth-first-search).
Returns
-------
pred : dictionary
Dictionary, keyed by node, of predecessors in the shortest path.
+
+ (pred, seen): tuple of dictionaries
+ If `return_seen` argument is set to `True`, then a tuple of dictionaries
+ is returned. The first element is the dictionary, keyed by node, of
+ predecessors in the shortest path. The second element is the dictionary,
+ keyed by node, of the level (number of hops) to reach the node (as seen
+ during breadth-first-search).
+
Examples
--------
>>> G = nx.path_graph(4)
@@ -490,6 +500,9 @@ def predecessor(G, source, target=None, cutoff=None, return_seen=None):
[0, 1, 2, 3]
>>> nx.predecessor(G, 0)
{0: [], 1: [0], 2: [1], 3: [2]}
+ >>> nx.predecessor(G, 0, return_seen=True)
+ ({0: [], 1: [0], 2: [1], 3: [2]}, {0: 0, 1: 1, 2: 2, 3: 3})
+
"""
if source not in G: