code: def 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
  
      Examples
      --------
      >>> G = nx.path_graph(5, create_using=nx.DiGraph())
      >>> length = 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
  
      See Also
      --------
      single_source_shortest_path_length, shortest_path_length
      """
      if target not in G:
          raise nx.NodeNotFound(f"Target {target} is not in G")
  
      warnings.warn(
          (
              "\n\nsingle_target_shortest_path_length will return a dict instead of"
              "\nan iterator in version 3.5"
          ),
          FutureWarning,
          stacklevel=3,
      )
  
      if cutoff is None:
          cutoff = float("inf")
      # handle either directed or undirected
      adj = G._pred if G.is_directed() else G._adj
      nextlevel = [target]
      # for version 3.3 we will return a dict like this:
      # return dict(_single_shortest_path_length(adj, nextlevel, cutoff))
      return dict(_single_shortest_path_length(adj, nextlevel, cutoff))
  
file_path: networkx/networkx/algorithms/shortest_paths/unweighted.py
imports: import warnings
  import networkx
label_desc: Use image node_id 3 for calling a global function with example usage: single_target_shortest_path_length(G, target, cutoff) and returns: dict