for w in words:
    for m in re.finditer(w, s):
        i = m.start()
for j in range(i, i + len(w)):
    x.add(j)
result = ''.join('x' if i in x else s[i] for i in range(len(s)))
print(result)
String coverage optimization in Python