Версия для слабовидящих: Вкл Изображения: Выкл Размер шрифта: A A A Цветовая схема: A A

You can solve this using a while loop to repeatedly find and remove the target substring until it no longer exists in the word.

While the CodeHS exercise often requires the manual loop approach above, the simplest way to do this in standard Python is using the .replace() method:

: If letter is an empty string, the loop would run forever; we return the original word immediately.

: word[:index] takes everything before the letter, and word[index + len(letter):] takes everything after it. Adding them together effectively "deletes" the unwanted part.

: This method returns the starting index of the first occurrence of letter . If it isn't found, it returns -1 .


7.6 / 10 123... Access

You can solve this using a while loop to repeatedly find and remove the target substring until it no longer exists in the word.

While the CodeHS exercise often requires the manual loop approach above, the simplest way to do this in standard Python is using the .replace() method:

: If letter is an empty string, the loop would run forever; we return the original word immediately.

: word[:index] takes everything before the letter, and word[index + len(letter):] takes everything after it. Adding them together effectively "deletes" the unwanted part.

: This method returns the starting index of the first occurrence of letter . If it isn't found, it returns -1 .

Стерлитамакский филиал УУНиТ