I am using this method to match a string with an array. However, I want to match entire words, instead of each character in a string.
string = "Take a pill when you are ill"
array = ['bill', 'chill', 'pill']
if any(x in string for x in array):
string = string.replace('ill', 'sick')
print(string)
I want this block of code to return:
Take a pill when you are sick
But it returns:
Take a psick when you are sick
How do I do this?