I have a list as below:
lst = ['for Sam', 'Just in', 'Mark Rich']
I am trying to remove an element from list of strings(string contains one or more words) which contains stopwords
.
As 1st and 2nd elements in the list contains for
and in
which are stopwords
, it will return
new_lst = ['Mark Rich']
What I tried
from nltk.corpus import stopwords
stop_words = set(stopwords.words('english'))
lst = ['for Sam', 'Just in', 'Mark Rich']
new_lst = [i.split(" ") for i in lst]
new_lst = [" ".join(i) for i in new_lst for j in i if j not in stop_words]
Which is giving me output as:
['for Sam', 'Just in', 'Mark Rich', 'Mark Rich']