There's a multitude of ways you could go about this, but let's choose the way you've done thus far.
So you split the sentence into words, which I imagine you accomplished through text = text.split(" ")
, so your list looks something like text = ["The", "quick", "brown", "fox.", "Jumped", "over", "the", "lazy", "dog."]
Now let's implement the period into this new array, new_list
.
text = text.split(" ")
new_list = [] # New list we will write the words to
for word in text:
if '.' in word:
word = word.split('.') # Here we assume period always comes after word
new_list.append(word[0])
new_list.append('.')
else:
new_list.append(word)
Now it appears you don't want words such as "The" or "over". For this, simply create another array, such as skip_words = ["The", "the", "over"]
.
skip_words = ["The", "the", "over"]
for word in skip_words:
new_list.remove(word)
And this should do the trick! Now just try printing out new_list
.