Removing Capitalized Strings from Input File in Python3.4?

From the code it would appear that your file is really a csv file (your are reading the file with csv.reader). Assuming that this is the case, the following should work:

def filtercaps(infilename,outfilename):

  import csv
  list_of_words=[]
  list=[]
  with open(infilename) as inputfile:
      for row in csv.reader(inputfile):
          list.append(row)
      for l in list:
          if len(l) == 0:
              continue
          first_entry = l[0]
          first_letter = first_entry[0][0]
          if first_letter in 'qwertyuiopasdfghjklzxcvbnm':
              list_of_words.append(l)
  f = open(outfilename, "w")
  writer = csv.writer(f)
  for l in list_of_words:
      writer.writerow(l)
  f.close()

filtercaps("Enable1.txt","Enable2.txt")

There are other things that one could do to make the script more idiomatic python.

Leave a Comment