title: how to make list of files in directory and process them one by one? - Python
body: <p>i want to make a list of all text files in a directory. then i want to create separate list of the contents in each file. e.g document1=[] and then document2=[] so on. and then by using document 1 and document 2 keywords i want to calculate term frequency and other processes. code is running but list cant be assigned different names as document1 and so on.</p>
  
  <pre><code>import glob
  import math
  import re
  
  a=0
  flist=glob.glob(r'D:/Final Year Project/Development process/Text_data_extraction/MyFolder/*.txt') #get all the files from the d`#open each file &gt;&gt; tokenize the content &gt;&gt; and store it in a set
  for fname in flist:         
      tfile=open(fname,"r")
      line=tfile.read()
      a+=1
      line = line.lower() # lowercase
      line = re.sub("&amp;lt;/?.*?&amp;gt;"," &amp;lt;&amp;gt; ",line) #remove tags
      line = re.sub("(\\d|\\W)+"," ",line)  # remove special characters and digits
      l_ist = line.split("\n")
      print 'document'
      print(l_ist)
  tfile.close() # close the file
  print"Number of documents:"
  print(a)
  </code></pre>