title: Python - Counting Words In A Text File
body: <p>I'm new to Python and am working on a program that will count the instances of words in a simple text file. The program and the text file will be read from the command line, so I have included into my programming syntax for checking command line arguments. The code is below</p>
  
  <pre><code>import sys
  
  count={}
  
  with open(sys.argv[1],'r') as f:
      for line in f:
          for word in line.split():
              if word not in count:
                  count[word] = 1
              else:
                  count[word] += 1
  
  print(word,count[word])
  
  file.close()
  </code></pre>
  
  <p>count is a dictionary to store the words and the number of times they occur. I want to be able to print out each word and the number of times it occurs, starting from most occurrences to least occurrences. </p>
  
  <p>I'd like to know if I'm on the right track, and if I'm using sys properly. Thank you!!  </p>