Created
February 6, 2022 22:52
-
-
Save Abuton/41cf829b6e0595fb94ace415bebeb57f to your computer and use it in GitHub Desktop.
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
def replace_word(roots: list, sentence: str) -> str: | |
output = [] | |
sentence_list = sentence.split() | |
for word in sentence_list: | |
output.append(word) | |
for r in roots: | |
if word.startswith(r): | |
output[-1] = r | |
return " ".join(output) | |
replace_word(roots=['cat', 'bat', 'rat'], sentence='the cattle was rattled by battery') |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment