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:
Text=list(Text.split())
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)
Inputs:
Text = "jack and jill went to the market to buy bread and cheese cheese is jack favorite food"
L1 = ["and","he","the","to","is"]
Desired Output:
['jack', 'jill', 'went', 'market', 'buy', 'bread', 'cheese', 'cheese', 'jack', 'favorite', 'food']
Actual Output:
['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?