Python implementation of five string operations
This file contains 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
from typing import Generator | |
def clean_up(s: str) -> str: | |
return next(split_into_sentences(fix_hyphenation(fix_whitespace(s)))) | |
def fix_whitespace(s: str) -> str: | |
return s.replace("\n", " ") | |
def fix_hyphenation(s: str) -> str: | |
return s.replace("- ", "") | |
def split_into_sentences(s: str) -> Generator[str, None, None]: | |
return (ensure_ends_with_period(sentence) for sentence in s.split(". ")) | |
def ensure_ends_with_period(sentence: str) -> str: | |
return sentence + ("" if sentence.endswith(".") else ".") |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment