def bellman_ford_path_length(G, source, target, weight='weight'):
 if (source == target):
  return 0
 weight = _weight_function(G, weight)
 length = _bellman_ford(G, [source], weight, target=target)
 try:
  return length[target]
 except KeyError:
  raise nx.NetworkXNoPath(('node %s not reachable from %s' % (source, target)))

def bellman_ford_path_length ( G , source , target , weight = 'weight' ) : if ( source == target ) : return 0 weight = _weight_function ( G , weight ) length = _bellman_ford ( G , [ source ] , weight , target = target ) try : return length [ target ] except KeyError : raise nx . NetworkXNoPath ( ( 'node %s not reachable from %s' % ( source , target ) ) )
returns the shortest path length from source to target in a weighted graph .