import re txt = "If the the problem is textual, use the the re module" txt = re.sub("the the", "the", txt) print(txt)