title: Enumerating all paths in a tree and manipulate values associated with each node
body: <p>Inspired by the <a href="https://stackoverflow.com/questions/5671486/enumerating-all-paths-in-a-tree/5671568#5671568">answer</a> to the <a href="https://stackoverflow.com/questions/5671486/enumerating-all-paths-in-a-tree/">question "Enumerating all paths in a tree"</a>, I wrote an adapted version (I don't need the unrooted path):</p>
  
  <pre><code>def paths(tree):
      #Helper function
      #receives a tree and 
      #returns all paths that have this node as root
      if not tree:
          return []
      else: #tree is a node
          root = tree.ID
          rooted_paths = [[root]]
          for subtree in tree.nextDest:
              useable = paths(subtree)
              for path in useable:
                  rooted_paths.append([root]+path)
      return rooted_paths
  </code></pre>
  
  <p>Now, in my "tree" object, I have a number associated with each node: tree.number. I looks like this:</p>
  
  <pre><code>     A,2
      /   \
    B,5   C,4
     |    /  \
    D,1  E,4 F,3
  </code></pre>
  
  <p>I would like to initialize my paths with a 0 value, and sum all tree.numbers of the path, in order to know the sum for each generated path:</p>
  
  <pre><code>A-B-D: 8
  A-C-E: 10
  A-C-F: 9
  </code></pre>
  
  <p>How should I modify my code to get this result? I'm not seeing how to do it.</p>