title: Determining the author of a certain text
body: <p>I have to determine if the author of a certain text inputted by the user is melville, shakespeare, or neither. I started off by finding the top 50 words and their ratio of occurrence for three of melvilles and shakespeares text and turning it into two seperate lists. I then did the same thing with the unknown text. I want to compare the unknown text's list with melville and shakespeare's list of top 50 words and their ratio of occurrence. If a word in the unknown text is in both melville and shakespeare then I want to compare the ratio of the words occurrence between melville and shakespeare. Which ever one has the highest occurrence, we will assume that its from the text. Preferably it would be good to go through all 50 words for a more accurate determination. This is my code so far:</p>
  
  <pre><code>def identifyAuthor(textFile):
      counts = {}
      A = []
      B = []
      C = []
  
      B = melville()
      C = shakespeare()
  
      for words in [textFile]:
          text = open(words, 'r').read()
          test = text.lower()
  
      for ch in '!"$%&amp;()*+,-./:;&lt;=&gt;?@[\\]^_`{|}~':
          text = text.replace(ch, ' ')
          words = text.split()
  
      for w in words:
          counts[w] = counts.get(w, 0) + 1
  
      items = list(counts.items())
      items.sort()
      items.sort(key=byFreq, reverse = True)
  
      for i in range(50):
          word, count = items[i]
          count = count / float(len(counts))
          A += [[word, count]]
  
      for i in range(50):
          part1 = filter(lambda x: i in x, A) 
          part2 = reduce(lambda x, y: x + y, part1)
      return part2[1]
  </code></pre>
  
  <p>The problem I am having is I am getting an error:</p>
  
  <p><code>TypeError: reduce() of empty sequence with no initial value</code>
  I am assuming this is because filter can't search a variable and has to search an actual string like 'the'? So I was wondering how I would get it to work with a variable or if I can't then what would be an alternative? Any help will be much appreciated.</p>