THE INVESTIGATION
The preference that loses its place
Equal-priority choices change order even though the caller supplied a preference.
CollectionsStateRegression testing
What’s going wrong
A preference list is ranked by specificity, then quality. Equal priorities must keep their incoming relative order.
Input is a JSON array of at most 200 records with name (short ASCII string), specificity (integer 0..3), and quality (integer 0..1000). Sort descending by specificity, then descending by quality. Preserve original relative order when both numbers tie. Print the names in ranked order as one JSON array. Zero quality is retained; this task ranks records rather than deciding acceptability. Repeated names are retained too.
Expected behavior
Distinguish intentional ordering rules from accidental tie-breakers.
Reproduction
01 Equal priorities preserve caller order
[{"name":"alpha","specificity":1,"quality":100},{"name":"zulu","specificity":1,"quality":100}]["alpha","zulu"]
02 Different quality controls ordering
[{"name":"a","specificity":1,"quality":2},{"name":"z","specificity":1,"quality":1}]["a","z"]
03 Specificity precedes quality
[{"name":"a","specificity":0,"quality":1000},{"name":"b","specificity":2,"quality":1}]["b","a"]
Before you begin
- Python lists and dictionaries
- Preserve every valid result and its required position.
Need a nudge?
Reveal one investigation hint at a time. Try each clue before opening the next.
The bug is intentional. Run the starter code to see it fail, then work toward a fix. Difficulty is provisional.
Ready when you are
Every fix starts with a failing test.
Read the report, then sign in to start your investigation.