I am trying to split some text into sentences, capitalize the first character of each sentence, and recombine the results into one string. However the capitalize()
is only happening on the first sentence. Why is that?
import re
slow = "fat chance. not going to happen! whatever next? give us break."
mylist = re.split('([.?!])', slow)
print(mylist) # check progress so far
out = []
for w in mylist:
if w not in ".?!":
w = w.capitalize() # Why does this only work the first time?
out.append(w)
print("".join(out))
# Output:
# ['fat chance', '.', ' not going to happen', '!', ' whatever next', '?', ' give us a break', '.', '']
# Fat chance. not going to happen! whatever next? give us a break.