list' object has no attribute 'split

671 Views Asked by At

as I understand I am trying to split the text i.e. input that we will get not the list, where am I going wrong?

While running the below code I am getting the error

AttributeError: 'list' object has no attribute 'split'
def remove_stopwords(text):
  x=[]
  for i in text.split():
  # checking if the splitted word is in above imported stopwords list, if  not, we are appending the word in an empty list
    if i not in stopwords.words('english'):
      x.append(i)
  # copying the content of x to y before clearing x and making iit ready for next iteration
  y=x[:]
  x.clear()
  return y
1

There are 1 best solutions below

0
Eyad Sibai On

the text variable you are providing to the function is of a type list instead of str. Either your text is a list of texts and you want to do splitting for each text. then you need to loop over each one and call the function.

list_of_textx = [remove_stopwords (text) for text in texts]

Or you want to call this line prior to call your function

text = ''.join(text)