Last Updated : 11 Jul, 2025
The problem is to determine if a string contains all the vowels: a, e, i, o, u. In this article, we’ll look at different ways to solve this.
Using all()all()
function checks if all vowels are present in the string. It returns True
if every condition in the list comprehension is met.
s = "Geeksforgeeks"
v = 'aeiou'
# check if each vowel exists in the string
if all(i in s.lower() for i in v):
print("True")
else:
print("False")
Let's understand more methods to accept the strings which contains all vowels .
Using set()
set()
function is used to store unique elements and can efficiently check if all vowels are present in a string.
s= "geeksforgeeks"
# Define set of vowels
v= set('aeiou')
# Check if all vowels are present in the string (case-insensitive)
if v.issubset(set(s.lower())):
print("True")
else:
print("False")
Using a Loop
Looping through the string, this method checks for the presence of each vowel. It stops early once all vowels are found, ensuring an efficient solution with linear time complexity.
Python
s = "education"
v = 'aeiou'
a= set()
# Loop through each character in `s`
for char in s.lower():
if char in v:
# Add the vowel to the found set
a.add(char)
if len(a) == 5:
# If all vowels are found, exit early
print("True")
break
else:
print("False")
Using regular expression
regular expression provide an efficient way to search for patterns in strings. This method uses regex to check if a string contains all five vowels (a, e, i, o, u), regardless of their order.
Python
import re
s = "geeksforgeeks"
# Check if all vowels are present using regex
if re.search(r'(?=.*a)(?=.*e)(?=.*i)(?=.*o)(?=.*u)', s.lower()):
print("True")
else:
print("False")
RetroSearch is an open source project built by @garambo | Open a GitHub Issue
Search and Browse the WWW like it's 1997 | Search results from DuckDuckGo
HTML:
3.2
| Encoding:
UTF-8
| Version:
0.7.4