Python – A sequence containing at least three consecutive vowels

A sequence containing at least three consecutive vowels… here is a solution to the problem.

A sequence containing at least three consecutive vowels

I’m trying to create a function to evaluate if at least three vowels are included in a row.

So far I’ve tried:
(I don’t know how to assess if they are continuous)
Any ideas?

def isConsecutive(word):
    # initialize vowel count
vCounter = 0
for letter in word:
    if letter == isVowel(word):  
        vCounter += 1
    else:
        vCounter = 0

if vCounter < 3:    
        return False
return True

Helper functions

def isVowel(char):
    return len(char) == 1 and char.lower() in 'aeiou'

Solution

Check that you have reached the third vovel in order, which should be after vCounter += 1. If there are three vovels: Returns true.

In addition, the isVowel check should be applied to letters, not to the entire word.

def isVowel(char):
    return char.lower() in 'aeiou'

def isConsecutive(word):
    # initialize vowel count
    vCounter = 0
    for letter in word:
        if isVowel(letter): # <= check if the letter is a vowel
            vCounter += 1
            if vCounter >= 3: # <= do the check right here
                return True
        else:
            vCounter = 0

return False # <= if we did not find three vovels in the loop, then there is none

print "hello: " + str(isConsecutive("hello"))
print "heeello: " + str(isConsecutive("heeello"))
print "hellooo: " + str(isConsecutive("hellooo"))

Try it online: DEMO

Related Problems and Solutions