I am trying to search for words in a file. Those words are stored in a separate list. The words that are found are stored in another list and that list is returned in the end.
The code looks like:
def scanEducation(file):
education = []
qualities = ["python", "java", "sql", "mysql", "sqlite", "c#", "c++", "c", "javascript", "pascal",
"html", "css", "jquery", "linux", "windows"]
with open("C:\Users\Vadim\Desktop\Python\New_cvs\\" + file, 'r') as file1:
for line in file1:
for word in line.split():
matching = [s for s in qualities if word.lower() in s]
if matching is not None:
education.append(matching)
return education
First it returns me a list with bunch of empty "seats" which means my comparison isn't working?
The result (scans 4 files):
"C:\Program Files (x86)\Python2\python.exe" C:/Users/Vadim/PycharmProjects/TestFiles/ReadTXT.py
[[], [], [], [], [], [], [], [], [], ['java', 'javascript']]
[[], [], [], [], [], [], [], [], [], ['pascal']]
[[], [], [], [], [], [], [], [], [], ['linux']]
[[], [], [], [], [], [], [], [], [], [], ['c#']]
Process finished with exit code 0
The input file contains:
Name: Some Name
Phone: 1234567890
email: some@email.com
python,excel,linux
Second issue each file containes 3 different skills, but the function finds only 1 or 2. Is it also a bad comparison or do I have a different error here?
I would expect the result being a list of just the found skills without the empty places and to find all the skills in the file, not just some of them.
Edit: The function does find all the skills when I do word.split(', ')
but if I would like it to be more universal, what could be a good way to find those skills if I don't know exactly what will separate them?