title: Python, iterating through a list to perform a search
body: <p>I hope someone can point out where I have gone wrong.  I am looking to iterate through the 'mylist' list to grab the first entry and use that first entry as a search string, then perform a search and gather particular information once the string is found and post it to an Excel worksheet.  Then I am hoping to iterate to the next 'mylist' entry and perform another search. The first iteration performs ok, but with the second iteration of the loop I get the following CMD window error...</p>
  
  <pre><code>2014 Apr 25  09:43:42.080  INFORMATION FOR A
  
  14.01
  Traceback (most recent call last):
  File "C:\TEST.py", line 362, in &lt;module&gt;
  duta()
  File "C:\TEST.py", line 128, in duta
  if split[10] == 'A':
  IndexError: list index out of range
  Exception RuntimeError: RuntimeError('sys.meta_path must be a list of 
  import hooks',) in &lt;bound method Workbook.__del__ of 
  &lt;xlsxwriter.workbook.Workbook object at 0x0238C310&gt;&gt; ignored
  </code></pre>
  
  <p>Here's my code...</p>
  
  <pre><code>for root, subFolders, files in chain.from_iterable(os.walk(path) for path in paths):
          for filename in files:  
              if filename.endswith('.txt'): 
  
                  with open(os.path.join(root, filename), 'r') as fBMA:
  
                      searchlinesBMA = fBMA.readlines()
                      fBMA.close()
  
                      row_numBMAA+=1 
  
                      num = 1
                      b = 1
                      print len(mylist)
                      print (mylist[num])
                      while b&lt;len(mylist):
                          for i, line in enumerate(searchlinesBMA):
                              for word in [mylist[num]]:
                                  if word in line:
                                      keylineBMA = searchlinesBMA[i-2]
                                      Rline = searchlinesBMA[i+10]
                                      Rline = re.sub('[()]', '', Rline)
                                      valueR = Rline.split()
                                      split = keylineBMA.split()
                                      if split[6] == 'A':
                                          print keylineBMA
                                          print valueR[3]
                                          worksheetFILTERA.write(row_numBMAA,3,valueR[3], decimal_format)
  
                                          row_numBMAA+=1
                                          break
  
                          num+=1
                          b=+1
  </code></pre>
  
  <p>Any ideas as to what I am doing wrong?  Is my loop out of position, or am I not inputting the correct list pointer?</p>
  
  <p>Thanks,
  MikG</p>