code: def branching_weight(G, attr="weight", default=1):
      """
      Returns the total weight of a branching.
  
      You must access this function through the networkx.algorithms.tree module.
  
      Parameters
      ----------
      G : DiGraph
          The directed graph.
      attr : str
          The attribute to use as weights. If None, then each edge will be
          treated equally with a weight of 1.
      default : float
          When `attr` is not None, then if an edge does not have that attribute,
          `default` specifies what value it should take.
  
      Returns
      -------
      weight: int or float
          The total weight of the branching.
  
      Examples
      --------
      >>> G = nx.DiGraph()
      >>> G.add_weighted_edges_from([(0, 1, 2), (1, 2, 4), (2, 3, 3), (3, 4, 2)])
      >>> nx.tree.branching_weight(G)
      11
  
      """
      return sum(
          edge[2].get(attr, default) for edge in G.edges(data=True)
      )
  
imports: import string
  from dataclasses import dataclass, field
  from enum import Enum
  from operator import itemgetter
  from queue import PriorityQueue
  import networkx
  from networkx.utils import py_random_state
  from .recognition import is_arborescence, is_branching
label_desc: Use image node_id 4 for calling a global function with example usage: branching_weight(G, attr, default) and returns: sum