string capitalize sentence

dimitri pater dimitri.pater at gmail.com
Thu Jun 23 18:54:21 EDT 2005


Hello!

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://www.serpia.com>
-------------- next part --------------
An HTML attachment was scrubbed...
URL: <http://mail.python.org/pipermail/python-list/attachments/20050624/910da0b6/attachment.html>


More information about the Python-list mailing list