def bellman_ford_path(G, source, target, weight='weight'):
 (lengths, paths) = single_source_bellman_ford(G, source, target=target, weight=weight)
 try:
  return paths[target]
 except KeyError:
  raise nx.NetworkXNoPath(('Node %s not reachable from %s' % (source, target)))

def bellman_ford_path ( G , source , target , weight = 'weight' ) : ( lengths , paths ) = single_source_bellman_ford ( G , source , target = target , weight = weight ) try : return paths [ target ] except KeyError : raise nx . NetworkXNoPath ( ( 'Node %s not reachable from %s' % ( source , target ) ) )
returns the shortest path from source to target in a weighted graph g .