Intermediate
Re-rank a shortlist and survive a failing re-ranker
Write rerank_safe(question, candidates, scorer, final_k). candidates is a list of ids in first-stage order, and scorer(question, candidate) returns a number (higher is better).
Return the best final_k candidates ordered by score, best first. Candidates with equal scores keep their first-stage order. If scorer raises any exception for any candidate, return candidates[:final_k] unchanged.
What Check tests
- Candidates are ordered by score
- Equal scores keep the first-stage order
- A failing scorer falls back to the first-stage order
- final_k larger than the list returns everything
- The scorer receives the question
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.