def _average_weight(G, path, weight=None):
 path_length = (len(path) - 1)
 if (path_length <= 0):
  return 0
 if (weight is None):
  return (1 / path_length)
 total_weight = sum((G.edge[i][j][weight] for (i, j) in pairwise(path)))
 return (total_weight / path_length)

def _average_weight ( G , path , weight = None ) : path_length = ( len ( path ) - 1 ) if ( path_length <= 0 ) : return 0 if ( weight is None ) : return ( 1 / path_length ) total_weight = sum ( ( G . edge [ i ] [ j ] [ weight ] for ( i , j ) in pairwise ( path ) ) ) return ( total_weight / path_length )
returns the average weight of an edge in a weighted path .