loading...

re: Daily Challenge #80 - Longest Vowel Change VIEW POST

FULL DISCUSSION
 

Hi,
this is my first time sharing my code here, so please don't judge :)
But I really like these little challenges, thank you!

Here we go (python ftw!):

def vowel(input):
        vowels = ['a','e','i','o','u']
        lengthes = []
        lastVowel = False
        for c in input:
                if c in vowels:
                        if not lastVowel:
                                lengthes +=[1]
                        else:
                                lengthes[len(lengthes)-1] += 1
                        lastVowel = True
                else:
                        lastVowel = False
        return max(lengthes)

print(vowel("codewarriors"))

There is probably some room for improvement...

Have a nice day!

 

Hi @heidrichj you could also use the class Counter from collections package :)

from typing import Union
from collections import Counter

def vowel(word: str) -> Union[int, None]:
    letters = ('a', 'e', 'i', 'o', 'u')
    letters_on_word = Counter(word)

    for letter, quantity in letters_on_word.most_common():
        if letter in letters:
            return quantity

Tip:

Always use tuple in a list that is "fixed" to ensure that this list will be immutable

code of conduct - report abuse