1
Guys, I’m doing a function to count the words of a text without repeating them and with that, I also need to count how many times it appears inside that list of strings I used the code below but it doesn’t work, I can’t get the position of the word on my word list to reference another list that will only store the amount of times it appears. Note: I need this to respect the position of the word with reference to position. Ex: words[1] = 'home' frequency[1] = 3
def frequencia(listTweets):
palavras = []
freq_palavras = []
for x in range(len(listaTweets)):
tweet = listaTweets[x]
listaP = separa_palavras(tweet)
for p in listaP:
if p in palavras:
indice = palavras.index(p)
freq_palavras[indice] += 1
else:
palavras.append(p)
return palavras, freq_palavras
The current code returns me this error: freq_palavras[Indice] += 1 Indexerror: list index out of range
– Jhonatan Teodoro
Hello Jhonatan! You can edit your question to include new information! :)
– Daniel