Article Categories
- All Categories
-
Data Structure
-
Networking
-
RDBMS
-
Operating System
-
Java
-
MS Excel
-
iOS
-
HTML
-
CSS
-
Android
-
Python
-
C Programming
-
C++
-
C#
-
MongoDB
-
MySQL
-
Javascript
-
PHP
Selected Reading
Remove Substrings in One Iteration in python
Suppose we have a string s, we have to remove all “y” and “xz” in the string in one iteration.
So, if the input is like s = "xyxxzyyxxzx", then the output will be xxxx
To solve this, we will follow these steps −
To solve this, we will follow these steps −
- temp := string after removing xz
- return temp after removing y
Let us see the following implementation to get better understanding −
Example
class Solution:
def solve(self, s):
return s.replace("xz","").replace("y","")
ob = Solution()
print(ob.solve("xyxxzyyxxzx"))
Input
"xyxxzyyxxzx"
Output
xxxx
Advertisements
