I am trying to search for words in a file. those words stored in a separate list.
Then if it finds it it stores in in another list and return the list in the end.
the code looks like:
education = 
"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:
"C:\Program Files (x86)\Python2\python.exe" C:/Users/Vadim/PycharmProjects/TestFiles/ReadTXT.py
[, , , , , , , , , ['pascal']]
[, , , , , , , , , ['linux']]
[, , , , , , , , , , ['c#']]
Process finished with exit code 0
Name: Some Name
You get empty lists because
None is not equal to an empty list. What you might want is to change the condition to the following:
if matching: # do your stuff
It seems that you're checking if a substring is present in the strings in the qualities list. Which might not be what you want. If you want to check the words on a line that appear on the qualities list, you might want to change your list comprehension to:
words = line.split() match = [word for word in words if word.lower() in qualities]
If you're looking into matching both
, and spaces, you might want to look into regex. See Python - Split Strings with Multiple Delimiters.