Workspace/Coding labs
Loading progress

Fuse candidate rankings

Intermediate50 min

Implement reciprocal_rank_fusion(rankings, k=60, limit=10). Rankings contain string document identifiers. Deduplicate each ranking while preserving first occurrence, assign compact ranks starting at 1, and sum 1/(k+rank). Return identifiers ordered by descending sum and ascending identifier for ties. Reject negative k or limit. This lab receives rankings as input; it does not create embeddings or contact a database.

Your task

  1. Complete the starter function using the contract above.
  2. Use the examples and visible tests to check normal inputs, boundaries, and rejected inputs.
  3. Run tests to record your result, then compare with the explained reference solution.

Examples

EXAMPLE 1

Input[[A,B,C],[B,D,A]], k=2

Output[B,A,D,C]

B gains the strongest combined contribution.
EXAMPLE 2

Input[[a,a,b],[b]], k=0

Output[b,a]

Repeated a in one branch contributes once.
solution.pyPython 3.12