Searching a file for words from a list
<p>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.</p>

<p>The code looks like:</p>

<pre><code>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
</code></pre>

<p>First it returns me a list with bunch of empty "seats" which means my comparison isn't working?</p>

<p>The result (scans 4 files):</p>

<pre><code>"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
</code></pre>

<p>The input file contains:</p>

<pre><code>Name: Some Name
Phone: 1234567890
email: some@email.com
python,excel,linux
</code></pre>

<p>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?</p>

<p>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.</p>

<p><strong>Edit</strong>: The function does find all the skills when I do <code>word.split(', ')</code>
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?</p>

<p>The code should be written as follows (if I understand the desired output format correctly):</p>

<pre><code>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:
        matching = []
        for word.lower() in line.strip().split(","):
            if word in qualities:
                matching.append(word)
        if len(matching) != 0:
            education.append(matching)
return education
</code></pre>

python python-2.7