Answered step by step
Verified Expert Solution
Link Copied!

Question

1 Approved Answer

Python You're on a website with a text field which autocompletes usernames as you type. Under the hood, there's an API call which takes in

Python

You're on a website with a text field which autocompletes usernames as you type. Under the hood, there's an API call which takes in the prefix of a username and then returns all usernames which start with that prefix, lexicographically sorted and truncated at 5 results. -lowercase ASCII letters Use this API call to dump the entire user database, specifically: Implement the `extract` function in `autocomplete.py`. `extract` should return the whole user database, making calls to `query` under the hood. 

autocomplete.py

def extract(query): """extract takes in a `query` API function (which returns the first 5 usernames, lexicographically sorted, that start with a prefix) and returns the sorted list of all usernames in the database. For example, the `query` function in provided in `main` works as follows: query("a") #=> ["abracadara", "al", "alice", "alicia", "allen"] query("ab") #=> ["abracadara"] The following implementation would pass the assertion in `main`, but is not a correct solution since it works only for that example `query`: def extract(query): return query("ab") + query("al") + query("altercation") + query("b") + query("el") + query("ev") + query("m") Your goal is to write an `extract` method that is correct for any provided `query`. """ # YOUR CODE HERE return [...] def main(): """Runs your solution -- no need to update (except to maybe try out different databases).""" # Sample implementation of the autocomplete API database = ["abracadara", "al", "alice", "alicia", "allen", "alter", "altercation", "bob", "element", "ello", "eve", "evening", "event", "eventually", "mallory"] query = lambda prefix: [d for d in database if d.startswith(prefix)][:5] assert extract(query) == database main() 

Step by Step Solution

There are 3 Steps involved in it

Step: 1

blur-text-image

Get Instant Access to Expert-Tailored Solutions

See step-by-step solutions with expert insights and AI powered tools for academic success

Step: 2

blur-text-image

Step: 3

blur-text-image

Ace Your Homework with AI

Get the answers you need in no time with our AI-driven, step-by-step assistance

Get Started

Students also viewed these Databases questions

Question

5. Identify three characteristics of the dialectical approach.

Answered: 1 week ago