Convert UPPERCASE string to sentence case in Python

Convert UPPERCASE string to sentence case in Python

Lets use an even more appropriate function for this: string.capitalize

>>> s=OPERATOR FAIL TO PROPERLY REMOVE SOLID WASTE
>>> s.capitalize()
Operator fail to properly remove solid waste

This will work for any sentence, or any paragraph. Note that the sentence must end with a . or it wont be treated as a new sentence. (Stealing .capitalize() which is the better method, hats off to brianpck for that)

a = hello. i am a sentence.
a = . .join(i.capitalize() for i in a.split(. ))

Convert UPPERCASE string to sentence case in Python

Leave a Reply

Your email address will not be published. Required fields are marked *