0

I have the following code which checks the words in each string in the list analysis_words for whether it is a stopword or not.

useful_word = []
for line in analysis_words:
    for word in line:
        if word.split() not in stopwords:
           useful_word.append(word)

I am attempting to do the same with list comprehension. My intuitive feeling was something like:

for line in analysis_words:
    useful_word = " ".join([word for word in line.split()if word not in 
    stopwords])

However, doing that splits the words into characters rather than the string "line" into words. I do not understand why this is the case. How should this be approached?

OgnjanD
  • 91
  • 1
  • 8

0 Answers0