I have two inputs (Text - a string, L1- List of strings to be excluded).
I have converted the 'Text' into a list and extracted each word and put it into a list using the following code:
Now I have to remove the words present in the L1 list from this 'Text' list. To do so, I used the following code:
for x in Text: if(x in L1): Text.remove(x) print(Text)
Text = "jack and jill went to the market to buy bread and cheese cheese is jack favorite food" L1 = ["and","he","the","to","is"]
['jack', 'jill', 'went', 'market', 'buy', 'bread', 'cheese', 'cheese', 'jack', 'favorite', 'food']
['jack', 'jill', 'went', 'the', 'market', 'buy', 'bread', 'cheese', 'cheese', 'jack', 'favorite', 'food']
Please tell me why is 'the' still present in the 'Text' ?
What did I do wrong? What should I do to get my desired result?