2
我只需要一些計算元音函數的幫助,就可以使函數返回比元音更多元音的單詞列表。計算函數中的元音
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']
看起來好,你是怎麼稱呼這個方法的? –
事實上,'mlk' var沒有'Our'這個詞,所以你做錯了別的東西或者只是一個錯字。 –
你也可以通過用'if letter.lower()in vowels'替換'if letter in vowels:'來減少你的元音到一個例子(例如較低) - 只是一個想法 –