title: Python: Parse text table and convert into nested data structure
body: <p>I need to parse a text table which has the following format:</p>
  
  <pre><code>-----------------------------------------
  | Serial |     Name             | marks |
  | Number |First | Middle | Last |       |
  -----------------------------------------
  | 1      | john |   s    |  doe |  56   |
  | 2      | jim  |   d    |  bill|  60   |
  </code></pre>
  
  <p>After parsing the table, the output should be a nested dictionary with the data as lists.</p>
  
  <pre><code>TableData = {'Serial Number':[1,2], 
               'Name': {'First':[john, jim]} 
                       {'Middle':[s, d]} 
                       {'Last':[doe, bill]}
               'marks': [56, 60]
              }
  </code></pre>
  
  <p>As of now I have logic to get the positions of the delimiters (|), and I can extract the text in between the delimiters.</p>
  
  <pre><code>posList = [[0,9,32,40],[0,9,16,25,32]]
  nameList = [['Serial','Name','marks'],['Number ','First','Middle','Last','  ']]
  </code></pre>
  
  <p>But I am having difficulty converting this to the nested dictionary structure.</p>