Convert UPPERCASE string to sentence case in Python

后端 未结 2 1659
终归单人心
终归单人心 2020-12-17 07:58

How does one convert an uppercase string to proper sentence-case? Example string:

\"OPERATOR FAIL TO PROPERLY REMOVE SOLID WASTE\"

Using

2条回答
  •  不知归路
    2020-12-17 08:34

    This will work for any sentence, or any paragraph. Note that the sentence must end with a . or it won't 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('. '))
    

提交回复
热议问题