Advertisement
Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- # Ввод строки
- s = input()
- # Ввод удаляемого слова
- sub = input()
- # Знаки препинания
- chars = ".,?!;:-"
- # Находим индекс удаляемого слова в строке
- pos = s.find(sub)
- # Пока слово есть в строке
- while pos != -1:
- # Находим индекс символа после слова
- char_index = pos + len(sub)
- # Если это знак препинания и сзади слова пробел - удаляем слово с пробелом
- if (char_index < len(s)) and (s[char_index] in chars) and (pos != 0) and (s[pos - 1] == ' '):
- s = s[:pos - 1] + s[char_index:]
- #Иначе просто удаляем слово
- else:
- s = s[:pos] + s[char_index:]
- # Обновляем индекс удаляемого слова в строке
- pos = s.find(sub)
- # Вывод результата
- print(s)
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement