title: Loop for Parsing complex tab delimited/csv files in Python
body: <p>Just to be clear, I'm very new to programming and I'm using Python 3.3! Right now I have a lot files in the same basic layout. Each file has 9 columns, tab delimited and a variable number of header lines - most have five lines though. There are NO headings for the rows or columns!  </p>
  
  <p>Looks something like this:</p>
  
  <pre><code>#header1
  #header2
  #header3
  #header4
  #header5
  ID1    asdf    asdk    asdfk    asdfkl    adsfkln    askdlfn   safsda    asdf    Notes1..
  ID2    asdf    asdk    asdfk    asdfkl    adsfkln    askdlfn   safsda    asdf    Notes2..
  ID3    asdf    asdk    asdfk    asdfkl    adsfkln    askdlfn   safsda    asdf    Notes3..
  ID4    asdf    asdk    asdfk    asdfkl    adsfkln    askdlfn   safsda    asdf    Notes4..
  </code></pre>
  
  <p>The only information that I want is the first column, which contains the IDs, and the last column which contains notes about each ID. I'm shooting for a dictionary something like this </p>
  
  <pre><code>{'ID1': [notes1...]
   'ID2': [notes2...]....
   'ID1234': [notes1234...]}
  </code></pre>
  
  <p>But I would be happy with a list of dictionaries as well or something like that. </p>
  
  <p>So I started by turning the text into a list of lists so that I can look up entries by index: </p>
  
  <pre><code>import csv
  
  list_all = list(csv.reader(open(r'complex_tabbed_file.gff', 'rb'), delimiter='\t'))
  
  d = dict()
  ID = data[5][0]     #starting at 5 to skip the header lines
  notes = data[5][8]
  d[ID]= notes
  
  print (d)
  </code></pre>
  
  <p>This gives me the info I am looking for but only reads one entry at I time. I need to create a loop that will read through the entire file which contains hundreds of entries..suggestions on a starting point? </p>
  
  <p>I researched and found this: <a href="https://stackoverflow.com/questions/16503560/read-specific-columns-from-csv-file-with-python-csv">Read specific columns from a csv file with csv module?</a> </p>
  
  <p>which describes a similar situation but the coding is a little over my head. As I'm a NEWBIE, I'm having a hard time applying this example to my particular case =( </p>
  
  <p>Here's what I have tried as far as iteration:</p>
  
  <pre><code>i=0
  
  if i &lt; 4:
      i= i+1
  
  if i &gt;= 5:
      ID = list_all[i][0]
      notes = list_all[i][8] 
      i= i+1
  
  print (d)
  </code></pre>
  
  <p>This returns an empty dictionary ( d={ } ) No good. </p>
  
  <p>Also tried</p>
  
  <pre><code>d = dict()  
  i=5
  for line in list_all: 
      ID = list_all[i][0]
      notes = list_all[i][8] 
      i = i+1
  
  print (d)
  </code></pre>
  
  <p>which gives the oh so lovely "list index out of range" error message. I would really appreciate any suggestions, thanks!</p>