title: 1D list to a complex nested? Indentation to parent-child relation
body: <p>The first list shows indentation levels of lines. The second one adds the parent child relationship. Using python how do I get from the first to the second?</p>
  
  <pre><code>indent=[0,1,2,2,2,3,2,3,4,5,5,5,4,2,1,0,1,1]
  
  parent_child=[[0,[1,[2,2,[2,[3]],[2,[3,[4,[5,5,5],4]]],2],1]],[0,[1,1]]]
  </code></pre>
  
  <p>Here is my code fragment so far:</p>
  
  <pre><code>pc=[]
  for i in indent: 
      if i &gt; pc[i-1]: 
          append
      if i == pc[i-1]: 
          if i+1 &gt; i+1: 
              append
              extend
  </code></pre>
  
  <p>the tricky part for me is getting ...2,[2,[3]] and not ..2,2,[3]</p>
  
  <pre><code>lastindent = -1
  print ("open list")
  for pos, i in enumerate(indent):
      currchange = i-lastindent
      try:
          nextindent = indent[pos+1]
      except(IndexError):
          print('close all lists')
      nextchange = nextindent-i
  
      if currchange &gt;0:
          print(" "*i+"open list (rule 1)")
          print(" "*i,i)
  
      if currchange==0 and nextchange==0:
          print(" "*i+" (rule 2)",i)
  
      if currchange== 0 and nextchange==1:
          print(" "*i+"open list (rule 3)")
          print(" "*i,i)
  
      if nextchange &lt; 0:
          print("Close (rule 4)")
  
      if currchange &lt; 0:
          print ("Close (rule 5")
          print(" "*i,i)
      ##needs more and accurate rules to get the nesting and closing right.
  
      lastindent = i
  </code></pre>
  
  <p>Some more unfinished code for illustration, nested HTML list is probably a better comparison.</p>