code: def branch2(tree):
      """walking a tree bottom-up based on dictionary"""
  
      if isinstance(
          tree, tuple
      ):  # assumes leaves are int for choice index
          name, subtree = tree
          print(name, data2[name])
          print("subtree", subtree)
          if testxb:
              branchsum = data2[name]
          else:
              branchsum = name  # 0
          for b in subtree:
              # branchsum += branch2(b)
              branchsum = branchsum + branch2(b)
      else:
          leavessum = sum(data2[bi] for bi in tree)
          print(
              "final branch with", tree, "".join(tree), leavessum
          )  # sum(tree)
          if testxb:
              return leavessum  # sum(xb[tree])
          else:
              return "".join(tree)  # sum(tree)
  
      print("working on branch", tree, branchsum)
      return branchsum
  
imports: from statsmodels.compat.python import lrange
  import numpy
label_desc: Use image node_id 2 for calling a global function with example usage: branch2(tree) and returns: branchsum, leavessum, str