Skip to main content
`Ctrl`+`K`

# single_target_shortest_path_length

single_target_shortest_path_length(G, target, cutoff=None)

  Compute the shortest path lengths to target from all reachable nodes.

  Parameters:
    G NetworkX graph
    target node

      Target node for path

    cutoff integer, optional

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

  Returns:
    lengths iterator

      (source, shortest path length) iterator

  See also

  `single_source_shortest_path_length`, `shortest_path_length`

  Examples

      >>> G = nx.path_graph(5, create_using=nx.DiGraph())
      >>> length = dict(nx.single_target_shortest_path_length(G, 4))
      >>> length[0]
      4
      >>> for node in range(5):
      ...     print(f"{node}: {length[node]}")
      0: 4
      1: 3
      2: 2
      3: 1
      4: 0