CodeWars: Vowel Count

The Problem

Given a string, count the number of vowels in it. The vowels are "aeiou" and the letters will be lower-cased.

The Solution

The Tests

# pypi
from expects import equal, expect

expect(vowel_count("a mouse is not a house")).to(equal(10))

The Function

VOWELS = set("aeiou")

def vowel_count(letters: str) -> int:
    """Counts the number of vowels in the input

     letters: lower-cased string to check for vowels

     count of vowels in the letters
    return sum(1 for letter in letters if letter in VOWELS)


One solution used regular expressions and the findall method. This seems better in a generalizable sense, but I think that the findall will build a list rather than a generator so might not be as efficient space-wise, and is probably slower. Others used the python string method - count. I think this problem is so easy that there's really not a lot of stuff you can do that doesn't overcomplicate things.

Anyway, day one.