# Find substrings that contain all vowels 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 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 −

Live Demo

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
Updated on 19-Aug-2020 11:28:19