subject

Write the autocorrect function, which takes as arguments a user_word, a list of all valid_words, a diff_function, and a limit. If the user_word is contained inside the valid_words list, autocorrect returns that word. Otherwise, autocorrect returns the word from valid_words that has the lowest difference from the provided user_word based on the diff_function. However, if the lowest difference between user_word and any of the valid_words is greater than limit, then user_word is returned instead. A diff function takes in three arguments, which are the two strings to be compared (first the user_word and then a word from valid_words), as well as the limit. The output of the diff function, which is a number, represents the amount of difference between the two strings. Assume that user_word and all elements of valid_words are lowercase and have no punctuation. Example of it working:>>> from cats import autocorrect, lines_from_file>>> abs_diff = lambda w1, w2, limit: abs(len(w2) - len(w1))>>> autocorrect("cul", ["culture", "cult", "cultivate"], abs_diff, 10)returns "cult"def autocorrect(user_word, valid_words, diff_function, limit):"""Returns the element of VALID_WORDS that has the smallest differencefrom USER_WORD. Instead returns USER_WORD if that difference is greaterthan LIMIT."""Important: if multiple strings have the same lowest difference according to the diff_function, autocorrect should return the string that appears first in valid_words.

ansver
Answers: 3

Another question on Computers and Technology

question
Computers and Technology, 21.06.2019 22:30
Aprovides legal protection for something an individual has created
Answers: 1
question
Computers and Technology, 23.06.2019 16:30
How to do this programming flowchart?
Answers: 3
question
Computers and Technology, 23.06.2019 22:30
Janice usually works on a particular workbook that contains all business related data. she decides to keep a backup of all the data in a separate workbook. she opens a new workbook to transfer the data. which option should she use to copy all the data from one workbook to another workbook?
Answers: 1
question
Computers and Technology, 24.06.2019 12:10
What is it called during the editing process when the processor ensures that a character holding a coffee mug from one angle is holding the same mug in the same way when the shot switches to another camera at another angle? cinematography continuity technology prop use
Answers: 1
You know the right answer?
Write the autocorrect function, which takes as arguments a user_word, a list of all valid_words, a d...
Questions
question
Mathematics, 19.05.2021 06:30
question
Mathematics, 19.05.2021 06:40
Questions on the website: 13722367