LLM Engineering · Exercise 1 of 6Next
Beginner
Build an inverted index
Write build_index(docs): docs is a dictionary from document name to text. Return a dictionary from each word to the sorted list of names of the documents that contain it (a document counts once per word, however often it repeats it).
Write search_all(index, query) that returns the sorted names of documents containing every word of the query. Words that no document has make the result empty, and an empty query returns []. Use the tokenize function given.
What Check tests
index["days"]is["returns", "shipping"](sorted)- A word repeated in one document lists it once
search_all(index, "unused days")is["returns"]- A word nobody has gives
[] - An empty query gives
[]
Stuck? One hint at a time
The solution unlocks after your first Check. Try first: that is where the learning happens.
main.py
Sign in to run your code.
Output
Press Run to see what your program prints.