Answered step by step
Verified Expert Solution
Link Copied!

Question

1 Approved Answer

You're on a website (such as Github!) with a text field which autocompletes usernames as you type. Under the hood, there's an API call which

You're on a website (such as Github!) 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.

Your task is to 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.

Code:

def extract(query): """Implement this method using the `query` API call, for example: query("abracadar") #=> ["abracadara"] using the default query method in main() """ # YOUR CODE HERE return [...]

def main(): """Runs your solution -- no need to update (except to maybe change the database).""" # Simple implementation of the autocomplete API database = ["abracadara", "al", "alice", "alicia", "allen", "alter", "altercation", "bob", "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

Recommended Textbook for

Modern Database Management

Authors: Jeffrey A. Hoffer Fred R. McFadden

4th Edition

0805360476, 978-0805360479

More Books

Students also viewed these Databases questions

Question

The Functions of Language Problems with Language

Answered: 1 week ago

Question

The Nature of Language

Answered: 1 week ago