title: Finding unique words in a specific text file and displaying a list of all the unique words found in the file python
body: <p>Write a program that opens a specified text file and then displays a list of all the unique words found in the file.<p>
  <i>HINT: Store each word as an element of a set</i></p>
  
  <pre><code>def main():
      # Open the text file
      text_file = open('for_exercise4.txt', 'r')
      read_file = text_file.readline()
  
      uniquewords = set([])
      print list(uniquewords)
  </code></pre>
  
  <p>This is what I've started with so far.
  After this I would need to display the unique words in that text file using a set.</p>
  
  <h1>EDIT</h1>
  
  <p>I've worked a little further into the exercise and this is what i came up with.</p>
  
  <pre><code>text_file = open(for_exercise4.txt, 'r')
  read_file = text_file.read()
  word_list = read_file.split()
  uniquewords = set[(word_list])
  
  for word in uniquewords:
      file.write(str(word) + "\n")
  file.close()
  
  print(uniquewords)
  </code></pre>
  
  <h1>EDIT #2</h1>
  
  <pre><code>def main():
      file = open("c://users/Brandon/Desktop/PythonClass/for_exercise4.txt", 'r')
      text = file.read()
      file.close()
  
      uniquewords = []
      word_list = text.split()
  
      for word in word_list:
          if word not in uniquewords:
              uniquewords.append(word)
              print(str(word))
      file.close()
  
  main()
  </code></pre>
  
  <p>When I run this it shows all the unique words but it doesn't store each word as an element of a set.</p>