Generation

generate functionMon, 27 Mar 2023

This code removes stopwords in lists incorrectly: without_sw = [[word for word in text if word not in stopwords_set] for text in only_words_text] It turns out like this: [[g], [u, n, l], [j, u, r, n, g], [p, n, ] It should be like this: [go, until, jurong, point Correct it.

from nltk.corpus import stopwords texts = [['go', 'until', 'jurong', 'point'], ['crazy', 'available', 'only', 'in', 'bugis', 'n', 'great', 'world', 'la', 'e', 'buffet', 'cine', 'there', 'got', 'amore', 'wat']] stopwords_set = set(stopwords.words('english')) without_sw = [word for text in texts for word in text if word not in stopwords_set]

Questions about programming?Chat with your personal AI assistant