I'm trying to write a program that compares each item in a list against the text of a document. The program should then return a new list with a value appended to each item of how many times it matched up against a word in the document. I have a function written that actually does the matching and it works fine on its own. The loop that does the counting also works for single entries. However, when I try to run it for all the entries of the list, it comes back with the proper number for the first list entry and then just gives zeroes back for the rest.
Here's an idea of what it looks like:
doc = open("C:/...")
list = ['string_1', 'string_2', 'string_3', ...]
answer = []
...
[some code]
...
for t in list:
counter = 0
for word in doc:
if func(word,t) == True:
counter += 1
answer.append([counter,t])
print answer
The closest thing to answering my question was this article. However, I do want to reset the counter for each list item and I haven't included the "counter = 0" in the actual "for" statement where the calculation is done.
I have a feeling that it may have to do with the placement of the "counter = 0" assignment, but if I place it outside the "for t in list:" loop, then it just returns the same value for every list entry.