Your problem is that the iterator for a string does not return every character, not every word.
For example:
>>> palabras = "Buenos dias" >>> [c for c in palabras] ['B', 'u', 'e', 'n', 'a', 's', ' ', 'd', 'i', 'a', 's']
You need to repeat and check every word, fortunately, the split function already exists in the python standard library in the string module . However, you are dealing with natural language, including punctuation, which you should look for here for a more reliable answer that the re module uses.
Once you have a list of words, you must enter them all before comparing, and then compare them as you have already shown.
Buena suerte.
EDIT 1
Try this code well, it should work for you. He shows two ways to do this, they are essentially identical, but the first is a little clearer, and the second is more pythons.
import re from nltk.corpus import stopwords scentence = 'El problema del matrimonio es que se acaba todas las noches despues de hacer el amor, y hay que volver a reconstruirlo todas las mananas antes del desayuno.'
Hope this helps you.
Jhsaunders
source share