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