3. Write a function called most_consonants(wordlist) that takes a list of lowerc
ID: 3586012 • Letter: 3
Question
3. Write a function called most_consonants(wordlist) that takes a list of lowercase words called wordlist and returns the word in the list with the most consonants. For example: most_consonantsCC'computer', 'science']) computer print(most_consonantsCC'obama', 'bush', 'clinton'])) clinton You don't need to worry about cases in which two or more words are tied for the most consonants. One thing that you'll need to solve this problem is a way to determine the number of consonants in a given word. We strongly encourage you to use as a helper function one of the functions that you wrote for parts 1 and 2 of this problem. Think about how you could use the value returned by one of those functions to determine how many consonants are in a given word. If you prefer, you are welcome to write a separate helper function that uses either recursion or a list comprehension to count the number of consonants in a word. We also strongly encourage you to use the list-of-lists technique that we discussed in lecture as the basis of your most_consonants function, but you may use recursion instead if you prefer.Explanation / Answer
def most_consonants(wordlist):
count = 0
answer = ""
for string in wordlist:
tmp=0
for i in range(len(string)):
if string[i]!='a' and string[i]!='e' and string[i]!='i' and string[i]!='o' and string[i]!='u':
tmp=tmp+1
if count<tmp:
count=tmp
answer=string
return answer
Related Questions
Hire Me For All Your Tutoring Needs
Integrity-first tutoring: clear explanations, guidance, and feedback.
Drop an Email at
drjack9650@gmail.com
drjack9650@gmail.com
Navigate
Integrity-first tutoring: explanations and feedback only — we do not complete graded work. Learn more.