Python Program: Counting vowels in a word
Python Counter Data Type: Exercise-3 with Solution
Write a Python program that creates a counter of the vowels in the word "Python Exercises".
Sample Solution:
Code:
from collections import Counter
word = "Python Exercises"
vowels = "aeiouAEIOU" # List of vowels
vowel_ctr = Counter(c for c in word if c in vowels)
print("Vowel Counts:")
for vowel, count in vowel_ctr.items():
print(f"{vowel}: {count}")
Output:
Vowel Counts: o: 1 E: 1 e: 2 i: 1
In the exercise above program, the "Counter" class counts the occurrences of each vowel in the given word. Each character in the word is checked to see if it is a vowel by the program. If it is a vowel, its count is updated in 'vowel_ctr'. Finally, the program prints the vowel counts.
Flowchart:

Previous: Python Program: Counting common elements in a list.
Next: Python Program: Counter operations - Union, intersection, and difference.
What is the difficulty level of this exercise?
Test your Programming skills with w3resource's quiz.
Python: Tips of the Day
Summing a sequence of numbers (calculating the sum of zero to ten with skips):
>>> l = range(0,10,2) >>> sum(l) 20
- Weekly Trends
- Python Interview Questions and Answers: Comprehensive Guide
- Scala Exercises, Practice, Solution
- Kotlin Exercises practice with solution
- MongoDB Exercises, Practice, Solution
- SQL Exercises, Practice, Solution - JOINS
- Java Basic Programming Exercises
- SQL Subqueries
- Adventureworks Database Exercises
- C# Sharp Basic Exercises
- SQL COUNT() with distinct
- JavaScript String Exercises
- JavaScript HTML Form Validation
- Java Collection Exercises
- SQL COUNT() function
- SQL Inner Join
We are closing our Disqus commenting system for some maintenanace issues. You may write to us at reach[at]yahoo[dot]com or visit us at Facebook