Reputation: 1
How can I search a single raw CSV file (contains list of a lot of words) in a text file in python. Or simply I just want to find a list of words and want to know if they are exist in my text file or not. How can I do that in python? Or if I can do that with a specific application that made for something like this let me know, I want to try that in excel but it can't import CSV or list of words in advance search. Thank you in advance
Upvotes: 0
Views: 120
Reputation: 11
Don't forget to change the name of your CSV file.
#!/usr/bin/python
import csv
from queue import Empty
import sys
#input the list of words you want to search and split words by SPACE
input_string = input('Enter elements of a list separated by space ')
string_list = input_string.split()
#read csv, and split on "," the line
csv_file = csv.reader(open('convertcsv.csv', "r"), delimiter=",")
total = set()
#loop through the csv list
for row in csv_file:
for field in row:
total.add(field)
list=[]
#add the matches to a list
for input in string_list:
if input in total:
if input not in list:
list+=[input]
#print the list
print(list)
Upvotes: 1