# global substitution def replace(str, old, new): list = str.split(old) # XoldY -> [X, Y] return new.join(list) # [X, Y] -> XnewY