sort-scores
---
id: sort-scores
title: Sort Tuples by Score - Solution
description: Write a function to sort a list of tuples, each containing a name and a score, in descending order by score
tags:
- Python
- Sorting
- Descending Order
sidebar_position: 11
isPublic: false
---
# Sort Tuples by Score - Solution
Explore three methods to sort a list of tuples by scores.
<br />
```python title="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.