code: def _pagerank_python(
      G,
      alpha=0.85,
      personalization=None,
      max_iter=100,
      tol=1.0e-6,
      nstart=None,
      weight="weight",
      dangling=None,
  ):
      if len(G) == 0:
          return {}
  
      D = G.to_directed()
  
      # Create a copy in (right) stochastic form
      W = nx.stochastic_graph(D, weight=weight)
      N = W.number_of_nodes()
  
      # Choose fixed starting vector if not given
      if nstart is None:
          x = dict.fromkeys(W, 1.0 / N)
      else:
          # Normalized nstart vector
          s = sum(nstart.values())
          x = {k: v / s for k, v in nstart.items()}
  
      if personalization is None:
          # Assign uniform personalization vector if not given
          p = dict.fromkeys(W, 1.0 / N)
      else:
          s = sum(personalization.values())
          p = {k: v / s for k, v in personalization.items()}
  
      if dangling is None:
          # Use personalization vector if dangling vector not specified
          dangling_weights = p
      else:
          s = sum(dangling.values())
          dangling_weights = {k: v / s for k, v in dangling.items()}
      dangling_nodes = [
          n for n in W if W.out_degree(n, weight=weight) == 0.0
      ]
  
      # power iteration: make up to max_iter iterations
      for _ in range(max_iter):
          xlast = x
          x = dict.fromkeys(xlast.keys(), 0)
          danglesum = alpha * sum(xlast[n] for n in dangling_nodes)
          for n in x:
              # this matrix multiply looks odd because it is
              # doing a left multiply x^T=xlast^T*W
              for _, nbr, wt in W.edges(n, data=weight):
                  x[nbr] += alpha * xlast[n] * wt
              x[n] += danglesum * dangling_weights.get(n, 0) + (
                  1.0 - alpha
              ) * p.get(n, 0)
          # check convergence, l1 norm
          err = sum(abs(x[n] - xlast[n]) for n in x)
          if err < N * tol:
              return x
      raise nx.PowerIterationFailedConvergence(max_iter)
  
imports: from warnings import warn
  import networkx
label_desc: Use image node_id 2 for calling a global function with example usage: _pagerank_python(G, alpha, personalization, max_iter, tol, nstart, weight, dangling) and returns: dict, x