Skip to main content
Practice

coding-quiz-4

---
id: coding-quiz-4
title: Coding Quiz - Sorting Tuples by Score
description: Write a function that sorts a list of tuples consisting of names and scores in descending order by the score.
tags:
- Coding Quiz
- Tuple
- Python
sidebar_position: 10
isPublic: false
---

# Coding Quiz - Sorting Tuples by Score

In this coding quiz, you are tasked with writing a function that sorts a list of tuples consisting of names and scores in descending order by the score.

For example, in the input list `[('Tom', 70), ('Jane', 88), ('Max', 95), ('Alice', 85)]`, the first tuple's `Tom` represents a name, and `70` represents a score.

Sort this list in descending order by the score, resulting in `[('Max', 95), ('Jane', 88), ('Alice', 85), ('Tom', 70)]`.

<br />

```python title="Write the Code"
def solution(scores):
# Write your code here
return



Constraints

  • The list contains at least one tuple.

  • Each tuple consists of a string and an integer, where the string represents a person's name and the integer represents the score.




Example

  • Input: [('Tom', 70), ('Jane', 88), ('Max', 95), ('Alice', 85)]

  • 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.