string capitalize sentence

dimitri pater dimitri.pater at gmail.com
Fri Jun 24 01:13:29 CEST 2005


thanks, a lot it works!
still learning something every day...
Dimitri

On 6/24/05, Skip Montanaro <skip at pobox.com> wrote:
> 
> 
> dimitri> I came up with the following solution:
> 
> dimitri> a = 'harry is a strange guy. so is his sister, but at least she 
> is not a
> dimitri> guy. i am.'
> dimitri> b = a.replace('. ', '.')
> dimitri> splitlist = b.split('.')
> dimitri> newlist = []
> dimitri> for i in range(len(splitlist)):
> dimitri> i = ''.join(splitlist[i].capitalize() + '.'
> dimitri> newlist.append(i)
> dimitri> cap = ' '.join(newlist).replace(' .', '')
> dimitri> print cap
> 
> No need for the replace(). Just split on ". ". No need for a for loop
> either, or the temp variable cap. Use a list comprehension. The result is:
> 
> print ". ".join([s.capitalize() for s in a.split(". ")])
> 
> Skip
> 



-- 
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/294b65ce/attachment.html>


More information about the Python-list mailing list