title: How can I get around the NoneType Error in python
body: <p>I have created the following function:</p>
  
  <pre><code>def rRWords(filename):
  infile = open(filename, "r")
  lines = infile.readlines()
  result = []
  for xx in lines:
        xx.lower
        result.append(xx.split(' ')[3])
  result.sort
  dic = {}
  for line in result:
        words = line.split()
        words = line.rsplit()
        for word in words :
              if word not in dic:
                    dic[word] = 1
  dic2 = {}
  for item in dic.items():
        if(item[0] == getWord(item[0])):
           #print(item[0])
           dic2[item[0]] = 1
  infile.close()
  filter(None, dic2)
  print(len(dic2))
  #print(*sorted(map(str.lower, dic2)), sep='\n')
  #return
  </code></pre>
  
  <p>When I use the function against a small file containing say 10 words it works.</p>
  
  <p>However when I run the checking function against this which uses a big text file with about 80000 words I get an error. The checkfunction is as below:</p>
  
  <pre><code>wordset = rRWords("master.txt")
  if len(wordset) == 80000 and type(wordset) is set:
      print("Well done Lucy Success!")
  else:
      print("Not good Lucy Failed")    
  </code></pre>
  
  <p>When I run this it prints to the whole text file to the screen (which I do not want) and at the end I get:</p>
  
  <pre><code>Traceback (most recent call last):
  File "C:\Users\jemma\Documents\checkscript.py", line 19, in &lt;module&gt;
  if len(wordset) == 80000 and type(wordset) is set:
  TypeError: object of type 'NoneType' has no len()
  </code></pre>
  
  <p>I just want this check function to run and output:</p>
  
  <pre><code>Well done Lucy Success!
  </code></pre>
  
  <p>Hope my edit to this question makes this clearer.</p>
  
  <p>Thanks in advance,
  Jemma</p>