I have to define a function vowelCount(). The input is a list of words and I have to return a dictionary which returns 3 keys. They are 'more consonants' which contains words which have more consonants than vowels, 'more vowels' which have more vowels and 'half vowels' which have equal amount of both.
Here is my code so far:
def voewlCount(wordList):
myDict = {}
vowelList = 'AEIOUaeiou'
contents = wordList.split()
for word in wordsList:
if vowelList in wordList == word:
myDict.append('half vowels')
elif vowelList in wordList > word:
myDict.append('more vowels')
else:
myDict.append('mostly consasants')
I am getting error messages when I run the shell, saying it is an attribute error sating that a dict has no attribute 'append'
I corrected my code but I am still having issues...here is my new code , Thank You for the help
def vowelContent(wordList):
myDict = {'more consonants':[],'more vowels':[],'half vowels':[]}
vowels = 'aeiouAEIOU'
for word in wordList:
if vowels in wordList < word:
myDict['more consonants'].append(word)
elif vowels in wordLists > word:
myDict['more vowels'].append(word)
else:
myDict['half vowels'].append(word)
return myDict
say = ['do', 'you','know','the','definition','of','insanity','or','being','insane']
print(vowelContent(say))
When I print the function, all the words from the list above are put into the 'more consonants' key
Here's some framework to help you get started. You can fill in the logic that I've left out.
def helper(word):
"""returns the number of vowels and consonants in the word, respectively"""
# you fill this in
return n_vowels, n_consonants
def voewlCount(wordList): #sic
result = {'more consonants': [], 'more vowels': [], 'half vowels': []}
for word in wordList:
nv, nc = helper(word)
if #something:
result['more consonants'].append(word)
elif #something_else:
result['more vowels'].append(word)
elif #the other thing:
result['half vowels'].append(word)
else:
# well this can never happen (or can it)?
return result
If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!
Donate Us With