title: Why the "List index out of range" error?
body: <p>So I have a list of files I want to read through and print this information out. It keeps giving me the error <code>list index out of range</code>. Not sure what was wrong. For line2, if I add <code>matches[:10]</code> it could work for the first 10 files. But I need it to do all files. Checked some old posts but still can not get mine code work. </p>
  
  <p><code>re.findall</code> worked before when I wrote this code in pieces. Not sure it is not working anymore. Thanks.</p>
  
  <pre><code>import re, os
  topdir = r'E:\Grad\LIS\LIS590 Text mining\Part1\Part1' # Topdir has to be an object rather than a string, which means that there is no paranthesis.
  matches = []
  for root, dirnames, filenames in os.walk(topdir):
      for filename in filenames:
          if filename.endswith(('.txt','.pdf')):
              matches.append(os.path.join(root, filename))
  
  capturedorgs = []
  capturedfiles = []
  capturedabstracts = []
  orgAwards={}
  for filepath in matches:
  with open (filepath,'rt') as mytext:
      mytext=mytext.read()
  
      matchOrg=re.findall(r'NSF\s+Org\s+\:\s+(\w+)',mytext)[0]
              capturedorgs.append(matchOrg)
  
      # code to capture files
      matchFile=re.findall(r'File\s+\:\s+(\w\d{7})',mytext)[0]
      capturedfiles.append(matchFile)
  
      # code to capture abstracts
      matchAbs=re.findall(r'Abstract\s+\:\s+(\w.+)',mytext)[0]
      capturedabstracts.append(matchAbs)
  
      # total awarded money
      matchAmt=re.findall(r'Total\s+Amt\.\s+\:\s+\$(\d+)',mytext)[0]
  
      if matchOrg not in orgAwards:
          orgAwards[matchOrg]=[]
      orgAwards[matchOrg].append(int(matchAmt))
  
  for each in capturedorgs:
      print(each,"\n")
  for each in capturedfiles:
      print(each,"\n")
  for each in capturedabstracts:
      print (each,"\n")
  
  # add code to print what is in your other two lists
  from collections import Counter
  countOrg=Counter(capturedorgs)
  print (countOrg)
  
  for each in orgAwards:
  print(each,sum(orgAwards[each]))
  </code></pre>
  
  <p>The error message:</p>
  
  <pre><code>Traceback (most recent call last):
    File "C:\Python32\Assignment1.py", line 17, in &lt;module&gt;
      matchOrg=re.findall(r'NSF\s+Org\s+\:\s+(\w+)',mytext)[0]
  IndexError: list index out of range
  </code></pre>