i have a list "total_vocabulary" with all the unique words in a collection of 56 documents. There is another list of list with words of every document "rest_doc". I want to calculate term frequency of each word from "total_vocabulary" in "rest_doc" so "term_freq" list will be a list of list of the same size of total_vocabulary and at each index of term_freq will be a list of size 56 representing the total occurrence of each word in each document. The problem is that the nested for loops are taking so much time,almost a minute to run. is there any way to do it faster? code:
for i in range(len(total_vocabulary)):
doc = []
for j in range(len(rest_doc)):
counter = 0
for k in range(len(rest_doc[j])):
if total_vocabulary[i] == rest_doc[j][k]:
counter = counter + 1
doc.append(counter)
term_freq.append(doc)
here is my code.