fork(4) download
  1. import re
  2.  
  3. def sentence_case(text):
  4. # Split into sentences. Therefore, find all text that ends
  5. # with punctuation followed by white space or end of string.
  6. sentences = re.findall('[^.!?]+[.!?](?:\s|\Z)', text)
  7.  
  8. # Capitalize the first letter of each sentence
  9. sentences = [x[0].upper() + x[1:] for x in sentences]
  10.  
  11. # Combine sentences
  12. return ''.join(sentences)
  13.  
  14. text = 'hello world. i know you hear me! where are you?'
  15. print(text)
  16. print(sentence_case(text))
  17.  
Success #stdin #stdout 0.1s 10088KB
stdin
Standard input is empty
stdout
hello world. i know you hear me! where are you?
Hello world. I know you hear me! Where are you?