title: Listing all paths to leaves in generic (non-binary) list-of-list tree
body: <p>I have a tree encoded in this way:</p>
  
  <pre><code>[A, [B, [G, [H], [I]]], 
      [D, [C], [E], [F]]]
  </code></pre>
  
  <p>This represents the following structure:</p>
  
  <pre><code>        A
         / \
        B   D
       /   /|\
      G   C E F
     / \
    H   I
  </code></pre>
  
  <p>Furthermore, the leaves all contain 'end' rather than an actual letter so H, I, C, E, F, are actually all 'end'</p>
  
  <p>Another way to view the list that might be more intuitive.  In this case, indentation represents the tree level</p>
  
  <pre><code>[A, 
      [B, 
          [G, 
              [H], 
              [I]
          ]
      ], 
      [D, 
          [C], 
          [E], 
          [F]
      ]
  ]
  </code></pre>
  
  <p>I want to traverse the tree and list all paths to leaves</p>
  
  <pre><code>[A, B, G, H]
  [A, B, G, I]
  [A, D, C]
  [A, D, E]
  [A, D, F]
  </code></pre>
  
  <p>I wrote this function that can traverse the tree and correctly identify leaves, but I'm not sure how to build the paths as lists like I have above:</p>
  
  <pre><code>def leave_paths(lst, level=0):
      #level is used to keep track how far in the tree we are to
      #perform various functions - removed here for simplicity
      if lst[0] == 'end':
          #This is a leaf!
      for i, l in enumerate(lst[1:]): 
          if type(l) is list:
              leave_paths(l, level + 1)
  </code></pre>
  
  <p>As far as I can tell this works right, but I'm not sure how to keep track of the paths such that they are formatted in the way I described.</p>