Find list of keywords in string
So I have a list of key words and I'm trying to check if any of those
words are found in a line in my csv sheet, if present, it should be
marked. The code I have works perfectly except when the line has more than
one of those keywords, it won't be marked. Thoughts?
import sys
import csv
nk = ('aaa','bbb','ccc')
with open(sys.argv[1], "rb") as f:
reader = csv.reader(f, delimiter = '\t')
for row in reader:
string=str(row)
if any(word in string for word in nk):
row.append('***')
print '\t'.join(row)
else:
print '\t'.join(row)
Thanks in advance!
No comments:
Post a Comment