Question
NEED HELP WITH THIS IN PYTHON #NOTE: Do not change your best function from the answer in #5 above! The best function should be able
NEED HELP WITH THIS IN PYTHON
#NOTE: Do not change your best function from the answer in #5 above! The best function should be able to take any scoring function and return the result. #Now pass a lambda function into your best function to find the name in names with the highest number of a's. This needs to be a lambda function and should only be one line!
#Example output:
#Madonna has the most a's.
#5
# Define a function, number_of_vowels, that returns the number of vowels in a string. Use it with your best function to find the name in names with the most vowels. def number_of_vowels(text): count = 0 for ch in text: if ch in "aeiouAEIOU": count += 1 return count
Create best function using instructions below
The following code defines a list of names and also contains a header for the function best. The best function takes two arguments: a generic scoring function, score, and a list of strings, names. Fill in the function so that it applies a score function to each string in the names list and returns the name with the highest score. If there are ties in the list, your function should return the first item with the maximum score. The best function needs to be designed so that it can take any scoring function and return the name with the highest score.
#For this, call the score function len_score and make this function return the length of the word.
#Example: #print(best(len_score, names), "has the longest name.") #McJagger has the longest name.
def best(score, names): # YOUR CODE HERE raise NotImplementedError()
names = ["Ben", "April", "Zaber", "Alexis", "McJagger", "J.J.", "Madonna"]
Step by Step Solution
There are 3 Steps involved in it
Step: 1
Get Instant Access to Expert-Tailored Solutions
See step-by-step solutions with expert insights and AI powered tools for academic success
Step: 2
Step: 3
Ace Your Homework with AI
Get the answers you need in no time with our AI-driven, step-by-step assistance
Get Started