My program in python to count the number of different words only returns the value six. Any ideas why?
Question: Here is my code. I am using Python:

    
    
    import re
    file = open('TEST.txt')
    text = file.read()
    file.close()
    words = list(text.split())
    myset= set(words)
    num = len(myset)
    print (num)
    

When I run it, it prints 6 no matter how long the text file is. Why would this
be and how would I fix it?


Answer: You are using a `set()`; your file consists of only six _unique_ words.
Repeating the same 6 words over and over again won't make the count go up.

Either don't use a set (which can only hold unique values), or use other words
in your file:

    
    
    >>> words = ['foo', 'bar', 'baz', 'foo', 'bar', 'baz']
    >>> len(words)
    6
    >>> len(set(words))
    3
    >>> set(words)
    set(['baz', 'foo', 'bar'])
    

You are also using a _relative_ filename; `TEST.txt` will be opened in the
current directory; change your current directory (in your terminal, using
`os.chdir()`, etc.) and a different file will be opened if there is _another_
`TEST.txt` file there.

Use `print(words)` to see if you are still opening the right text file, check
for the current directory with `import os; print(os.getcwd())`, or better
still, use an absolute file path (with all the directories specified
explicitly).

