DEV Community

Discussion on: Daily Challenge #3 - Vowel Counter

Collapse
 
hectorpascual profile image
Héctor Pascual

Python

Given the list :

vowels = ['a', 'e', 'i', 'o', 'u']

We can define a function:

def vowels_count(word):
    count = 0
    for vowel in vowels:
        count += word.lower().count(vowel)
    return count

Or simply in a one-liner:

vowel_count = lambda word: len([char for char in word if char in vowels])