I have a list containing many suggestions. I want to iterate over the list, removing words like "and", "", "a", "is" from all sentences, etc.
I tried this:
def removearticles(text):
articles = {'a': '', 'an':'', 'and':'', 'the':''}
for i, j in articles.iteritems():
text = text.replace(i, j)
return text
As you can probably say, this will remove “a” and “an” when it appears in the middle of the word. I need to delete only instances of words when they are limited by a space, and not when they are inside a word. What is the most efficient way to do this?
source
share