Sort Tuples by Score - Solution
Explore three methods to sort a list of tuples by scores.
Method 1
def solution(scores):
return sorted(scores, key=lambda x: x[1], reverse=True)
Using the code above, you can sort the input list scores
in descending order by scores.
Example Usage
Input/Output Example
scores = [('Tom', 70), ('Jane', 88), ('Max', 95), ('Alice', 85)]
result = solution(scores)
print(result) # Output: [('Max', 95), ('Jane', 88), ('Alice', 85), ('Tom', 70)]
Want to learn more?
Join CodeFriends Plus membership or enroll in a course to start your journey.