|
| 1 | +"""Functions to help edit essay homework using string manipulation.""" |
| 2 | + |
| 3 | + |
| 4 | +def capitalize_title(title: str) -> str: |
| 5 | + """ |
| 6 | + Convert the first letter of each word in the title to uppercase if needed. |
| 7 | +
|
| 8 | + :param title: str - title string that needs title casing. |
| 9 | + :return: str - title string in title case (first letters capitalized). |
| 10 | + """ |
| 11 | + |
| 12 | + return title.title() |
| 13 | + |
| 14 | + |
| 15 | +def check_sentence_ending(sentence: str) -> bool: |
| 16 | + """ |
| 17 | + Check the ending of the sentence to verify that a period is present. |
| 18 | +
|
| 19 | + :param sentence: str - a sentence to check. |
| 20 | + :return: bool - return True if punctuated correctly with period, |
| 21 | + False otherwise. |
| 22 | + """ |
| 23 | + |
| 24 | + return sentence[-1] in ".!?" |
| 25 | + |
| 26 | + |
| 27 | +def clean_up_spacing(sentence: str) -> str: |
| 28 | + """ |
| 29 | + Verify that there isn't any whitespace at the start and end of the |
| 30 | + sentence. |
| 31 | +
|
| 32 | + :param sentence: str - a sentence to clean of leading and trailing |
| 33 | + space characters. |
| 34 | + :return: str - a sentence that has been cleaned of leading and |
| 35 | + trailing space characters. |
| 36 | + """ |
| 37 | + |
| 38 | + return sentence.strip() |
| 39 | + |
| 40 | + |
| 41 | +def replace_word_choice(sentence: str, old_word: str, new_word: str) -> str: |
| 42 | + """ |
| 43 | + Replace a word in the provided sentence with a new one. |
| 44 | +
|
| 45 | + :param sentence: str - a sentence to replace words in. |
| 46 | + :param old_word: str - word to replace. |
| 47 | + :param new_word: str - replacement word. |
| 48 | + :return: str - input sentence with new words in place of old words. |
| 49 | + """ |
| 50 | + |
| 51 | + return sentence.replace(old_word, new_word) |
0 commit comments