I am trying to count the number of occurrences of words from a list. I need the result to be (word, # of occurrence) however I keep getting (word, 1) (word, 2) (word,3), when it should be giving me (word,3).
All the variables of library, document, and dictionary are defined in another area.
I believe my code is 99% correct but the result is not doing what I need it to.
def (word_search) :
results = []
search_word = dictionary [0]
for search_word in dictionary:
count = 0
for document in library:
for word in document:
if search_word == word :
count = count + 1
results.append((word,count))
return (results)