I want to replace each instance of a character in one string with a character at the same index in another string. If no character exists at that index, leave it as it is.
Here's my solution with a list comprehension (Python 3):
string1 = "food is delicious"
string2 = "orange is not delicious"
string3 = "".join([string2[i] if i<len(string2) and c=="o" else c for i, c in enumerate(string1)])
print(string3)
Result
frad is delicidus
It feels like there should be a better way though, for example using str.replace somehow. Any ideas?