Count vowels in a file

EasyFile Handling Programs · 34 of 38

Write a Python program to count the vowels in a file.

Advertisement
Output
8

Approach

  1. Count characters in “aeiou” after lower-casing.

Solution

Python
with open("story.txt", "w") as f:    f.write("Python file handling is easy\n") with open("story.txt") as f:    print(sum(ch in "aeiou" for ch in f.read().lower()))
Output
8
Advertisement

Learn the concept

New to this topic? Read the lesson, then come back.

More file handling programs

← All 38 File Handling Programs