
- 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
Find substrings that contain all vowels in Python
Suppose we have a string in lowercase alphabets, we have to find substrings that contain all the vowels at least once and there exist no consonants in that substrings.
So, if the input is like "helloworldaeiouaieuonicestring", then the output will be ['aeiou', 'aeioua', 'aeiouai', 'aeiouaiu', 'eioua', 'eiouai', 'eiouaiu']
To solve this, we will follow these steps −
n := size of s
for i in range 0 to n, do
my_map := a new map
for j in range i to n, do
if s[j] not vowel, then
come out from the loop
my_map[s[j]] := 1
if size of my_map is same as 5, then
display s[from index i to j + 1]
Example
Let us see the following implementation to get better understanding −
def isVowel(x): if x in ['a','e','i','o','u']: return True return False def get_substrings(s): n = len(s) for i in range(n): my_map = dict() for j in range(i, n): if (isVowel(s[j]) == False): break my_map[s[j]] = 1 if (len(my_map) == 5): print(s[i:j + 1]) s = "helloworldaeiouaiunicestring" get_substrings(s)
Input
"helloworldaeiouaiunicestring"
Output
aeiou aeioua aeiouai aeiouaiu eioua eiouai eiouaiu
- Related Articles
- Java program to accept the strings which contain all vowels
- Python - Find all the strings that are substrings to the given list of strings
- Find all possible substrings after deleting k characters in Python
- Count the number of vowels occurring in all the substrings of given string in C++
- Program to find sum of beauty of all substrings in Python
- Program to find longest substring of all vowels in order in Python
- Find all substrings in a string using C#
- Find all substrings combinations within arrays in JavaScript
- Program to find all substrings whose anagrams are present in a string in Python
- Python Program to find out the size of the bus that can contain all the friends in the group
- Program to find out the substrings of given strings at given positions in a set of all possible substrings in python
- C# Program to find all substrings in a string
- C# program to check for a string that contains all vowels
- Python program to accept the strings which contains all vowels
- Program to find total sum of all substrings of a number given as string in Python

Advertisements