title: Change a file to a list to a dictionary
body: <p>I am trying to write a code that takes the text from a novel and converts it to a dictionary where the keys are each unique word and the values are the number of occurrences of the word in the text.<br>
  For example it could look like: {'the': 25, 'girl': 59...etc}</p>
  
  <p>I have been trying to make the text first into a list and then use the Counter function to make a dictionary of all the words:</p>
  
  <pre><code>    source = open('novel.html', 'r', encoding = "UTF-8")
      soup = BeautifulSoup(source, 'html.parser')
      #make a list of all the words in file, get rid of words that aren't content
      mylist = []
      mylist.append(soup.find_all('p'))
      newlist = filter(None, mylist)
      cnt = collections.Counter()
      for line in newlist:
           try:
             if line is not None:        
                 words = line.split(" ")
                 for word in line:
                  cnt[word] += 1
           except:
             pass
      print(cnt)
  </code></pre>
  
  <p>This code doesn't work because of an error with "NoneType" or it just prints an empty list.  I'm wondering if there is an easier way to do what I'm trying to do or how I can fix this code so it won't have this error.</p>