Sort Students by Marks
Given a list of (name, marks) pairs, use sorted() with a key and lambda to sort students by marks in descending order.
Approach: read each student as a name and a mark, build a list of tuples, then call sorted(..., key=lambda s: s[1], reverse=True).
Input: First line: the number of students n. Next n lines: name marks, space-separated.
Output: One line: the students sorted by marks descending, printed as a Python list of tuples.
3 Aditi 85 Rohan 92 Zara 78
[('Rohan', 92), ('Aditi', 85), ('Zara', 78)]- 1 <= n <= 1000
Hint 1
key=lambda s: s[1] tells sorted() to compare by the second item of each tuple (the marks).
Hint 2
reverse=True sorts from highest to lowest instead of the default ascending order.
sorted(students, key=lambda s: s[1], reverse=True) tells Python to compare tuples by their second element (marks) rather than the tuple as a whole, and reverse=True flips the order to descending. Equal marks keep their original relative order, since Python's sort is stable.