import re
def replace_last_occurrence(s, old, new):
old_idx = s.rfind(old)
if old_idx == -1:
return s
return s[:old_idx] + new + s[old_idx + len(old):]
s = "Python programming high-level programming general-purpose programming language"
old = "programming"
new = "ABC"
result = replace_last_occurrence(s, old, new)
print(result)
'''
run:
Python programming high-level programming general-purpose ABC language
'''