import re contractions = { r"(?", r"(?", r"(?", r"(?", r"(?", r"(?", r"(?", r"(?", r"(?", r"(?", r"(?", r"(?", r"(?", r"(?", r"(?", r"(?", r"(?", r"(?", r"(?", r"(?", r"(?", r"(?", r"(?", r"(?", r"(?", r"(?", r"(?", r"(?", r"(?", r"(?", r"(?", r"(? str: """ Replace contractions to their based form. Parameters ---------- text: str Text that may contain contractions. Returns ------- str: Text with expanded contractions. """ for contraction in contractions.keys(): replace_str = contractions[contraction] text = replace_keep_case(contraction, replace_str, text) return text