I'm attempting to write a program in python that searches ~27,000 rows for each string in a list. Each string I am searching for is in one column, and has an 'id' value in another column that I would like printed if found. The code I currently have counts the number of times that string appears in the document, but I am still unable to find a way to return specific values for each unique row in which the strings are found.
import csv
fin = open('data.csv')
words = ["happy","sad","good","bad","sunny","rainy"]
found = {}
count = 0
for line in fin:
for word in words:
if word in line:
count = count + 1
found[word] = count
print(found)
The main semantic problem with the code above is that printing the 'found' dictionary only yields one of the results and its count from the 'words' list.