I am trying to do simple 'NLP' in python using functions.
For some reason whenever I run my code, the first string works fine, however I get an error message ('list index out of range') whenever I run the second string.
def sentence_to_words(s):
s=s.lower()
s=s.split(" ")
lst=["$", "#", "%", "!", "?", ".", ","]
for i in range(len(s)):
s[i]=list(s[i])
while s[i][0] in lst:
del s[i][0]
while s[i][-1]in lst:
del s[i][-1]
s[i]=''.join(s[i])
return (s)
print sentence_to_words("Will this work?")
print sentence_to_words("Mr. Stark ... I don't feel so good")
the end result for both should be:
['will' , 'this' , 'work']
["mr" , "stark" , "i" , "don't" , "feel" , "so" , "good"]
But the second one doesn't actually run, and I get an error message instead.