Capitalization of each sentence in a string in Python 3

后端 未结 5 1134
-上瘾入骨i
-上瘾入骨i 2021-01-22 10:25

This should be easy but somehow I\'m not quite getting it.

My assignment is:

Write a function sentenceCapitalizer that has one parameter of type

5条回答
  •  不思量自难忘°
    2021-01-22 10:28

    Just because I couldn't find this solution here.

    You can use 'sent_tokenize' method from nltk.

    import nltk
    string = "hello. my name is Joe. what is your name?"
    sentences = nltk.sent_tokenize(string)
    print (' '.join([s.replace(s[0],s[0].capitalize(),1) for s in sentences]) )
    

    And the output

    Hello. My name is Joe. What is your name?
    

提交回复
热议问题