I have a text file which have normal sentences. Actually I was in hurry while typing that file so I just capitalized the first letter of first word of the sentence (as per English grammar).
But now I want that it would be better if each word's first letter is capitalized. Something like:
Each Word of This Sentence is Capitalized
Point to be noted in above sentence is of and is are not capitalized, actually I want to escape the words which has equal to or less than 3 letters.
What should I do?
for line in text_file:
print ' '.join(word.title() if len(word) > 3 else word for word in line.split())
Edit: To omit counting punctuation replace len
with the following function:
def letterlen(s):
return sum(c.isalpha() for c in s)
If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!
Donate Us With