DEV Community

loading...

Discussion on: Daily Challenge #80 - Longest Vowel Change

Collapse
rafaacioly profile image
Rafael Acioly • Edited

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

Forem Open with the Forem app