- Trending Categories
- Data Structure
- Operating System
- C Programming
- Selected Reading
- UPSC IAS Exams Notes
- Developer's Best Practices
- Questions and Answers
- Effective Resume Writing
- HR Interview Questions
- Computer Glossary
- Who is Who
Python program to count the number of vowels using set in a given string
In this program, given a user input string. We have to count number of vowels in this string. Here we use set in Python. Set is an unordered collection data type that is iterable, mutable and no duplicate elements.
Input : str1=pythonprogram Output : 3
Step 1: First we use one counter variable which is used to count the vowels in the string. Step 2: Creating a set of vowels. Step 3: Then traverse every alphabet in the given string. Step 4: If the alphabet is present in the vowel set then counter incremented by 1. Step 5: After the completion of traversing print counter variable.
# Program to count vowel in # a string using set def countvowel(str1): c = 0 # Creating a set of vowels s="aeiouAEIOU" v = set(s) # Loop to traverse the alphabet # in the given string for alpha in str1: # If alphabet is present # in set vowel if alpha in v: c = c + 1 print("No. of vowels ::>", c) # Driver code str1 = input("Enter the string ::>") countvowel(str1)
Enter the string ::> pythonprogram No. of vowels ::> 3
- Python program to count number of vowels using set in a given string
- Python program to count the number of vowels using sets in a given string
- How to Count the Number of Vowels in a string using Python?
- Java program to count the number of vowels in a given sentence
- C# Program to count number of Vowels and Consonants in a string
- C++ Program to count Vowels in a string using Pointer?
- Count the number of vowels occurring in all the substrings of given string in C++
- C# Program to count vowels in a string
- Java Program to count vowels in a string
- Count the pairs of vowels in the given string in C++
- To count Vowels in a string using Pointer in C++ Program
- Java Program to count all vowels in a string
- Java Program to Count the Number of Vowels and Consonants in a Sentence
- C Program to count vowels, digits, spaces, consonants using the string concepts
- How to find the vowels in a given string using Java?