Beginner
Build an inverted index and answer AND queries
docs is a dict of passage id to text, and tokenize(text) is given. Write build_index(docs) returning a dict from term to the list of passage ids that contain it (each id once, in the order of docs).
Write match_all(index, words) returning the list of ids that contain every word, in the order of the first word's postings. A word missing from the index means no passage matches: return [].
What Check tests
- Postings list the passages that contain a term
- A repeated word lists the passage once
- AND keeps passages with every word
- A missing word gives no match
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.