class WordFilter: def strip(self, str_1, str_2): str_1 = str_1.lower() str_2 = str_2.lower() i = 0 while True: if str_2[i:i+len(str_1)] == str_1: str_2 = str_2[:i] + str_2[len(str_1)+i:] i = 0 else: i += 1 if i >= len(str_2) - 1: return str_2 ''' This program takes as input two strings. The first of which is the search string and the second is the buffer to search. The object of the program is to remove all traces of the search string in the search buffer. The program will perform the search starting at the beginning of the buffer and continue until either the end of the buffer is reached or the search string is found. If the search string is found, the string should be removed, and the search should restart again from the beginning of the buffer. This process should repeat until a full search through the buffer produces no more matches. Requirements : 1. the search should be completely case-insensitive (ie "StRinG" should remove the phrase "sTrINg") 2. it should be a multi-pass filter (ie "string" should remove the phrase "strSTRINGing" Here is the method signature : public String strip(String str, String buf); We will check to make sure the input to this problem is valid. Here are some examples assuming the search string is "StRinG" : "ccccstring ssssssssss" -> "cccc ssssssssss" "ccccstrinstringgsssssssssss" -> "ccccsssssssssss" "ccccstring stringssssssssss" -> "cccc ssssssssss" test ab aabb '''
Run
Reset
Share
Import
Link
Embed
Language▼
English
中文
Python Fiddle
Python Cloud IDE
Follow @python_fiddle
Browser Version Not Supported
Due to Python Fiddle's reliance on advanced JavaScript techniques, older browsers might have problems running it correctly. Please download the latest version of your favourite browser.
Chrome 10+
Firefox 4+
Safari 5+
IE 10+
Let me try anyway!
url:
Go
Python Snippet
Stackoverflow Question