# Program to check one string can be converted to another by removing one element in Python

PythonServer Side ProgrammingProgramming

#### Beyond Basic Programming - Intermediate Python

Most Popular

36 Lectures 3 hours

#### Practical Machine Learning using Python

Best Seller

91 Lectures 23.5 hours

#### Practical Data Science using Python

22 Lectures 6 hours

Suppose we have two strings s and t, we have to check whether we can get t by removing 1 letter from s.

So, if the input is like s = "world", t = "wrld", then the output will be True.

To solve this, we will follow these steps −

• i:= 0
• n:= size of s
• while i < n, do
• temp:= substring of s[from index 0 to i-1] concatenate substring of s[from index i+1 to end]
• if temp is same as t, then
• return True
• i := i + 1
• return False

Let us see the following implementation to get better understanding −

## Example

Live Demo

class Solution:
def solve(self, s, t):
i=0
n=len(s)
while(i<n):
temp=s[:i] + s[i+1:]
if temp == t:
return True
i+=1
return False
ob = Solution()
s = "world"
t = "wrld"
print(ob.solve(s, t))

## Input

"world", "wrld"

## Output

True