I want to capitalize every sentence in a string:
harry is a strange guy. so is his sister, but at least she is not a guy. i am.
to:
Harry is a strange guy. So is his sister, but at least she is not a guy. I am.
I came up with the following solution:
a = 'harry is a strange guy. so is his sister, but at least she is not a guy. i am.'
b = a.replace('. ', '.')
splitlist = b.split('.')
newlist = []
for i in range(len(splitlist)):
i = ''.join(splitlist[i].capitalize() + '.'
newlist.append(i)
cap = ' '.join(newlist).replace(' .', '')
print cap
and it prints : Harry is a strange guy. So is his sister, but at least she is not a guy. I am.
But I wonder if there is a easier way to accomplish this. For instance it doesn't work with:
is harry a strange guy? so is his sister, but at least she is not a guy. i am.
any suggestions?
Thanks,
Dimitri
--
Please visit dimitri's website: www.serpia.com
-- http://mail.python.org/mailman/listinfo/python-list