Given a string, count the number of vowels present in given string using Sets.
Prerequisite: Sets in Python
Input : GeeksforGeeks Output : No. of vowels : 5 Input : Hello World Output : No. of vowels : 3
1. Create a set of vowels using set() and initialize a count variable to 0.
2. Traverse through the alphabets in the string and check if the letter in the string is present in set vowel.
3. If it is present, the vowel count is incremented.
Below is the implementation of above approach:
No. of vowels : 5
Attention geek! Strengthen your foundations with the Python Programming Foundation Course and learn the basics.
To begin with, your interview preparations Enhance your Data Structures concepts with the Python DS Course.
- Count the number of vowels occurring in all the substrings of given string
- Program to count vowels in a string (Iterative and Recursive)
- Program to count vowels, consonant, digits and special characters in string.
- Count the pairs of vowels in the given string
- Queries to find the count of vowels in the substrings of the given string
- Find the player to last modify a string such that even number of consonants and no vowels are left in the string
- Python program to find common elements in three lists using sets
- Python | Count and display vowels in a string
- Count number of rotated strings which have more number of vowels in the first half than second half
- Program to remove vowels from a String
- Program to duplicate Vowels in String
- Check if a string can be converted to another string by replacing vowels and consonants
- Reverse vowels in a given string
- Minimum swaps required to move all vowels occurs after consonants in a given string
- Minimize cost to replace all the vowels of a given String by a single vowel
- Minimum cost to convert given string to consist of only vowels
- Convert vowels into upper case character in a given string
- Count of substrings consisting of even number of vowels
- Encrypt string with product of number of vowels and consonants in substring of size k
- Python | Program to accept the strings which contains all vowels
If you like GeeksforGeeks and would like to contribute, you can also write an article using contribute.geeksforgeeks.org or mail your article to email@example.com. See your article appearing on the GeeksforGeeks main page and help other Geeks.
Please Improve this article if you find anything incorrect by clicking on the "Improve Article" button below.
Improved By : shubham_singh