title: How to do the program that able to show the top 10 keywords in text file, in python
body: <p>i am working on the program that able to show the top 10 keywords in the text file. The following are the step that i already did:</p>
  <ol>
  <li>open the file</li>
  <li>do the list of pairs</li>
  <li>and sorted the pairs</li>
  </ol>
  <p>after sorted my program got error. the paragraph below is my code.</p>
  <pre><code>filename = 'alice.txt'
  
  try:
      with open(filename, encoding='utf-8') as f_obj:
          contents = f_obj.read()
  except FileNotFoundError:
      msg = 'Sorry, the file ' + filename + 'does not exist. '
      print(msg)
  else:
      words = contents.split()
  
      
  wordfreq = []
  for w in words:
      wordfreq.append(words.count(w))
      
  
  pairs = str(list(zip(words, wordfreq) ))
  for key , value in pairs.items():
      print(&quot;Pairs\n&quot; + str(list(zip(words, wordfreq))))
      
  #print(&quot;Frequencies\n&quot; + str(wordfreq) + &quot;\n&quot;)
  #print(&quot;Pairs\n&quot; + str(list(zip(words, wordfreq))))    
  #print(max(str(list(zip(words, wordfreq)))))
      
  
  
  #print(max(int(list(wordfreq,words))))
    
      
  #print(&quot;List\n&quot; + str(words) + &quot;\n&quot;)
  
  #    num_words = len(words)
  #    print(&quot;The file &quot; + filename + &quot; has about &quot; + str(num_words) + &quot; words. &quot;)
  </code></pre>