text = input("anything: ")
text = text.lower() # ловер - а сами написали Черт
cen = {"черт":"####"}
for key, value in cen.items():
text = text.replace(key, value)
print(text)
Но такой заменит и чертежника
text = input("anything: ")
text = text.lower()
text_split = text.split()
cen = {"черт":"####"}
for key, value in cen.items():
for i in range(len(text_split)):
if text_split[i] == key:
text_split[i] = value
а такой уже нет
Ответ:
def list_to_str(list_ob):
ret = ""
for i in list_ob:
ret+=f"{i} "
ret = ret.replace("\\n", "\n")
return ret
text = """
черт
мой чертежник"""
text = text.lower()
text_split = text.replace("\n", "\\n").split()
cen = {"черт":"####"}
for key, value in cen.items():
for i in range(len(text_split)):
if text_split[i] == key:
text_split[i] = value
print(list_to_str(text_split))
Однако, такой не уберет "черт,", "чёрт!" и тд., а только "черт"