I am trying to replace two lists a text:
text = "today is friday july 1 2018"
days = ['monday', 'tuesday', 'wednesday', 'thursday', 'friday', 'saturday', 'sunday']
daysRegex = re.compile('|'.join(map(re.escape, days)))
months = ['january', 'february', 'march', 'april', 'may', 'mai', 'june', 'july', 'august', 'september', 'october', 'november', 'december']
monthsRegex = re.compile('|'.join(map(re.escape, months)))
replaces = daysRegex.sub("<day>", text) and monthsRegex.sub("<month>", text)
print(replaces)
output:
today is friday < month> 1 2018
correct output:
today is < day> < month> 1 2018
I'm not sure I'm using the and operator correctly. I'm just trying to put into practice what I studied about it (but I may have misunderstood)