mediumUnit 6 · Lists & Tuples
P18. Rank List
Lists & Tuples
Read n students with their marks and store each as a tuple (name, marks) in a list. Sort the list by marks from highest to lowest; students with equal marks are sorted by name alphabetically. Use sorted() with a lambda key.
Print the rank list, then print the top student's tuple.
Input Format
- Line 1:
n - Next
nlines:name marks
Output Format
nlines in the form<rank>. <name> - <marks>- Last line:
Top: <tuple>
Constraints
- 1 ≤
n≤ 50 - Names are single words
- 0 ≤ marks ≤ 100
Sample Test Cases
Sample 1
Input
4 ravi 78 anu 92 kiran 78 meena 65
Output
1. anu - 92
2. kiran - 78
3. ravi - 78
4. meena - 65
Top: ('anu', 92)Sample 2
Input
1 sam 50
Output
1. sam - 50
Top: ('sam', 50)Submitting checks 2 sample cases and 2 hidden test cases.