Advanced
Apply the access filter before ranking
Write visible(docs, role) returning the docs this role may see. Each doc is a dict with keys id, text and access. Docs with access "public" are visible to everyone and "staff" docs only to the role "staff".
Write search(docs, role, question, k) that first filters with visible, then scores each doc as the number of different lower-cased words shared with the question (letters and digits only), and returns the ids of the top k docs with a score above 0, best first, ties in list order.
What Check tests
- Public sees only public docs
- Staff sees everything
- A restricted doc never appears for the public
- Staff gets the restricted doc first
- No overlap means no results
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.