remove stopwords from list of strings python

Solutions on MaxInterview for remove stopwords from list of strings python by the best coders in the world

showing results for - "remove stopwords from list of strings python"
Lavana
05 Mar 2020
1from nltk.corpus import stopwords
2stopwords=set(stopwords.words('english'))
3
4data =['I really love writing journals','The mat is very comfortable and I will buy it again likes','The mousepad is smooth']
5
6def remove_stopwords(data):
7    output_array=[]
8    for sentence in data:
9        temp_list=[]
10        for word in sentence.split():
11            if word.lower() not in stopwords:
12                temp_list.append(word)
13        output_array.append(' '.join(temp_list))
14    return output_array
15
16
17
18
19
20output=remove_stopwords(data)
21
22print(output)
23['really love writing journals','mat comfortable buy likes', 'mousepad smooth']
24