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
def replace_ending(sentence, old, new): | |
# Check if the old string is at the end of the sentence | |
if sentence.endswith(old): | |
# Using i as the slicing index, combine the part | |
# of the sentence up to the matched string at the | |
# end with the new string | |
#i = sentence.index(old) | |
i= sentence[0:-len(old)] | |
new_sentence = i+new | |
return new_sentence |