- Trending Categories
Data Structure
Networking
RDBMS
Operating System
Java
iOS
HTML
CSS
Android
Python
C Programming
C++
C#
MongoDB
MySQL
Javascript
PHP
Physics
Chemistry
Biology
Mathematics
English
Economics
Psychology
Social Studies
Fashion Studies
Legal Studies
- Selected Reading
- UPSC IAS Exams Notes
- Developer's Best Practices
- Questions and Answers
- Effective Resume Writing
- HR Interview Questions
- Computer Glossary
- Who is Who
Check if a string can be converted to another string by replacing vowels and consonants in Python
Suppose we have two strings s and t. We can only change a character at any position to any vowel if it is already a vowel or to a consonant if it is already a consonant. We have to check whether s can be represented to t or vice-versa.
So, if the input is like s = "udpmva", t = "itmmve", then the output will be True as we can transform u -> i, d -> t, p -> m, a -> e
To solve this, we will follow these steps −
- s_size := size of s
- if s_size is not same as size of t , then
- return False
- for i in range 0 to s_size, do
- if s[i] and t[i] are vowels, then
- go for next iteration
- otherwise when s[i] and t[i] are not vowels, then
- go for next iteration
- otherwise,
- return False
- if s[i] and t[i] are vowels, then
- return True
Let us see the following implementation to get better understanding −
Example
def isVowel(x): if x in ['a', 'e', 'i', 'o', 'u']: return True return False def solve(s, t): s_size = len(s) if (s_size != len(t)): return False for i in range(s_size): if (isVowel(s[i]) and isVowel(t[i])): continue elif ((isVowel(s[i])) == False and ( isVowel(t[i]) == False)): continue else: return False return True s, t = "udpgma", "itmmve" print(solve(s, t))
Input
"udpgma", "itmmve"
Output
True
- Related Articles
- Program to check one string can be converted to another by removing one element in Python
- How to check if a string can be converted to float in Python?
- Check if a string can be repeated to make another string in Python
- Check if a string can be obtained by rotating another string 2 places in Python
- Check if a string can be formed from another string using given constraints in Python
- Check if matrix can be converted to another matrix by transposing square sub-matrices in Python
- 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
- Program to check one string can be converted to other by shifting characters clockwise in Python
- Check If a String Can Break Another String in C++
- C# Program to count number of Vowels and Consonants in a string
- Check if given string can be formed by concatenating string elements of list in Python
- Program to check whether one string can be 1-to-1 mapped into another string in Python
- How to count number of vowels and consonants in a string in C Language?
- Check if a string can be rearranged to form special palindrome in Python

Advertisements