Created
January 26, 2019 18:39
-
-
Save megaserg/2f5051e91ddaa42550ac28ef7d32de68 to your computer and use it in GitHub Desktop.
Capitalizes your text to make it look professional.
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
#!/usr/bin/env python | |
import re | |
import sys | |
def remove_double_space_dots(s): | |
while " " in s: | |
s = s.replace(" ", " ") | |
while ".." in s: | |
s = s.replace("..", ".") | |
return s | |
def capitalize_first_in_sentence(s): | |
def to_upper(match): | |
return match.group(1) + match.group(2).upper() | |
s = re.sub(r"(^\s*)(\w)", to_upper, s) # start of the text | |
s = re.sub(r"(\n\n\s*)(\w)", to_upper, s) # new paragraph | |
s = re.sub(r"([\.\?\!]\s*)(\w)", to_upper, s) # new sentence | |
return s | |
def capitalize_i(s): | |
return re.sub(r"(\s)i([\'\s])", r"\1I\2", s) # "I am" and "I'm" | |
s = "".join(sys.stdin.readlines()) | |
s = remove_double_space_dots(s) | |
s = capitalize_first_in_sentence(s) | |
s = capitalize_i(s) | |
print(s) |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment