Skip to main content
 首页 » 编程设计

python之计算函数中的元音

2024年11月01日8thcjp

<分区>

我只是需要一些关于计算元音的函数的帮助,该函数用于返回元音比辅音多的单词列表。

def moreVowels(text): 
    vowels = 'AEIOUaeiou' 
    words = text.split() 
    returnList = [] 
    for word in words: 
        vowelCount = 0 
        for letter in word: 
            if letter in vowels: 
               vowelCount += 1 
        if vowelCount > len(word)/2: 
           returnList.append(word) 
    return returnList 
 
mlk = 'Our lives begin to end the day we become silent about things that matter' 
 
print(moreVowels(mlk)) 

当我打印这个函数时,它返回了两次,不知道为什么。

['Our','Our','about','about']