Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

How do you capitalize the first word and every word after a period?

Tags:

python

So far I'm able to capitalize the first word of the sentence, but I need every first letter after a period to be capitalized. This is what I have:

def main():
    input1 = input('Enter your input here: ')
    capitalize = str.capitalize(input1)
    print("The capitalized version:", capitalize)

main()
like image 222
Gene Avatar asked Nov 17 '25 05:11

Gene


1 Answers

Use Sentence Case of the rename package.

>>> from tl.rename.case import transform_sentence_case
>>> transform_sentence_case(['foo bar baz', 'FOO bar. baz Asdf'])
['Foo bar baz', 'Foo bar. Baz asdf']

Or you could use a regex...

\.\s*([a-z])

Captialise the $1 capturing group.

like image 146
alex Avatar answered Nov 19 '25 20:11

alex