Python Program to Count the Number of Each Vowel

Python Program to Count the Number of Each Vowel: In this program, you’ll learn to count the number of each vowel in a string using the dictionary and list comprehension.

https://trans4mind.com/counterpoint/index-health-fitness/remedies-childs-constipation.html?fbclid=IwAR257lvNWFXKFhJSLd3AtblOImaHHHWqAnDacH8c3ChK9BBqzdOaOU3KU0Q

In this article, we will go through few of the popular methods to do this in an efficient manner.

Python Program to Count the Number of Each Vowel

Source Code

# Program to count the number of each vowels

# string of vowels
vowels = 'aeiou'

ip_str = 'Hello, have you tried our tutorial section yet?'

# make it suitable for caseless comparisions
ip_str = ip_str.casefold()

# make a dictionary with each vowel a key and value 0
count = {}.fromkeys(vowels,0)

# count the vowels
for char in ip_str:
   if char in count:
       count[char] += 1

print(count)

Output