
- Python Basic Tutorial
- Python - Home
- Python - Overview
- Python - Environment Setup
- Python - Basic Syntax
- Python - Comments
- Python - Variables
- Python - Data Types
- Python - Operators
- Python - Decision Making
- Python - Loops
- Python - Numbers
- Python - Strings
- Python - Lists
- Python - Tuples
- Python - Dictionary
- Python - Date & Time
- Python - Functions
- Python - Modules
- Python - Files I/O
- Python - Exceptions
Program to check one string can be converted to another by removing one element in Python
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
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
- Related Articles
- Program to check one string can be converted to other by shifting characters clockwise in Python
- Program to check whether one point can be converted to another or not in Python
- Program to check whether one string can be 1-to-1 mapped into another string in Python
- Check if a string can be converted to another string by replacing vowels and consonants in Python
- Check if matrix can be converted to another matrix by transposing square sub-matrices in Python
- How to check if a string can be converted to float in Python?
- Add one Python string to another
- Check if characters of one string can be swapped to form other in Python
- Check if it is possible to transform one string to another in Python
- Check if a string can be repeated to make another string in Python
- Java Program to check whether one String is a rotation of another.
- Write a program in C++ to check if a string can be obtained by rotating another string by two places
- Write a program in Java to check if a string can be obtained by rotating another string by 2 places
- Check if a string can be obtained by rotating another string 2 places in Python
- Java Program to construct one String from another

Advertisements