title: how to fix error TypeError: list indices must be integers or slices, not str in python
body: <p>based on the previous question i changed my code but still not working.
  <a href="https://stackoverflow.com/questions/60648501/how-to-count-the-frequency-of-words-existing-in-a-text-using-nltk/60648925?noredirect=1#comment107308482_60648925">click here </a></p>
  
  <p>I have a python script that reads the text and applies preprocess functions in order to do the analysis.
  The problem is that I want to count the frequency of words but the system crash and displays the below error.</p>
  
  <blockquote>
    <p>File "F:\AIenv\textAnalysis\setup.py", line 219, in tag_and_save
        file.write(word+"/"+tag+" (frequency="+ freq_tagged_data[word] +")\n") </p>
    
    <p>TypeError: list indices must be integers or slices, not str</p>
  </blockquote>
  
  <pre><code>def get_freq(tagged):
      freq_dist = {}
      freqs = FreqDist(tagged)
      freq_dist = [(word, freq) for word ,freq in freqs.items()]
      # print(freq_dist)
      return freq_dist
  
  def tag_and_save(tagger,text,path):
      clt = clean_text(text)
      tagged_data = tagger.tag(clt)
      tagged_data = sorted(tagged_data,key=operator.itemgetter(1))
      freq_tagged_data = get_freq(tagged_data)
      file = open(path,"w",encoding = "UTF8")
      for word,tag in tagged_data:
          file.write(word+"/"+tag+" (frequency="+ freq_tagged_data[word] +")\n")
      file.close()
  </code></pre>
  
  <p>if i try to convert word into int() </p>
  
  <pre><code>def tag_and_save(tagger,text,path):
      clt = clean_text(text)
      tagged_data = tagger.tag(clt)
      tagged_data = sorted(tagged_data,key=operator.itemgetter(1)) 
      freq_tagged_data = get_freq(tagged_data)
      file = open(path,"w",encoding = "UTF8")
      for word,tag in tagged_data:
          file.write(word+"/"+tag+" (frequency="+ freq_tagged_data[int(word)] +")\n")
      file.close()
  </code></pre>
  
  <p>it display the below error :</p>
  
  <blockquote>
    <p>File "F:\AIenv\textAnalysis\setup.py", line 219, in tag_and_save
        file.write(word+"/"+tag+" (frequency="+ freq_tagged_data[int(word)] +")\n") ValueError: invalid literal for
    int() with base 10: ''</p>
  </blockquote>
  
  <p>the expected output must be like this :</p>
  
  <p><strong>('*****/DTNN') 3</strong></p>