Menu
CoddyTech

Recap: Stable Ranking

Lesson 21 of 48 in Coddy's Python for C# Developers course.

challenge icon

Challenge

Beginner

Read nonnegative n, then n lines of name score, then an integer minimum score. Names are lowercase words; scores are integers. Keep records whose score meets the minimum. Sort by descending score while preserving input order for ties. Duplicate names remain separate records. Output position name score, numbering from one, or none when no record remains. The starter handles parsing.

C# transfer checkpoint

LINQ OrderByDescending and Python sorted are stable. Keep whole records so tied names retain their input order.

C# reference excerpt: executable statements assume using System; type-only excerpts illustrate the declared contract.

var scores = new[] { 2, 5, 5 };
var ranked = System.Linq.Enumerable.OrderByDescending(scores, x => x);
Console.WriteLine(string.Join(",", ranked));

Python pattern

scores = [2, 5, 5]
ranked = sorted(scores, reverse=True)
print(",".join(str(x) for x in ranked))

Editable implementation files: main.py. The locked driver.py is the supplied launcher or input/output harness and must remain unchanged.

Use the supplied input contract without prompts. Print only the required lines, each ending in a newline.

Try it yourself

# Starts the program in main.py. Edit main.py to solve the challenge.
from runpy import run_module

run_module("main", run_name="__main__")

All lessons in Python for C# Developers

Practice on your own: Online Python compiler