Answer the question
In order to leave comments, you need to log in
How to find and remove a word from a string?
First, a natural number N is introduced — the number of useful tips.
Useful tips are introduced on the next N lines. It is guaranteed that the length of each is at
least 3 characters.
Output Format:
You should print the same tips in the same order, but those that start with the word
"not" (which can also be written as "Not") and a
space do not need to print this initial "not" and a space .
Example:
Input:
3
Мой руки перед едой!
Не суй пальцы в розетку!
Берегись автомобиля!
Conclusion:Мой руки перед едой!
суй пальцы в розетку!
Берегись автомобиля!
Answer the question
In order to leave comments, you need to log in
Aloya228 's solution wo n't work here, as his code will remove all prefixes of non- and similar word fragments from the text.
We'll have to use regular expressions:
import re
# Из text будут удалены слова "не"
result = re.sub(r'\b[нН][еЕ]\b\s', '', text)
print(result)
# Из text будет удалена подстрока "не ", если она находится в самом начале строки
result = re.sub('^[нН][еЕ] ', '', text)
Didn't find what you were looking for?
Ask your questionAsk a Question
731 491 924 answers to any question