I have a problem with my list comprehension in python. I have a string variable with search queries, like this:
queries = 'news, online movies, weather, golden rush, online sports, price
of the golden ring, today weather, python'
And I have a list of 2 elements:
words = [ 'online', 'golden' ]
And I need to filter queries string with the list words, such that the final result will not include queries which have 'online' and 'golden' in its content.
I've tried this, but it doesn't work properly:
filteredquerry = []
queriesNew = queries.split(',')
for x in queriesNew:
if x not in words:
filteredquerry.append(x)
else:
break
print(filteredquerry)
Also I have tried another way of list 'filtering' using a list methods, but it gives me an error or gives back an empty list:
print( [ x for x in queries if x not in words ]
The expected result should look like this:
filteredquerry = ['news', 'weather', 'today weather', 'python']