﻿ Python: Find a tuple, the smallest second index value from a list of tuples - w3resource

# Python: Find a tuple, the smallest second index value from a list of tuples

## Python List: Exercise - 60 with Solution

Write a Python program to find a tuple, the smallest second index value from a list of tuples.

Visual Presentation: Sample Solution:

Python Code:

``````# Define a list 'x' containing tuples, where each tuple has two elements
x = [(4, 1), (1, 2), (6, 0)]

# Use the 'min' function to find the minimum element in the list 'x' based on a custom key
# The 'key' argument specifies a lambda function that calculates a key for each element in 'x'
# The lambda function computes the key as a tuple, where the first element is the second element of the tuple (n),
# and the second element is the negation of the first element (-n)
# This effectively sorts the tuples first by their second element in ascending order and then by their first element in descending order
# The 'min' function returns the tuple with the minimum key value
print(min(x, key=lambda n: (n, -n)))
```
```

Sample Output:

```(6, 0)
```

Flowchart: Python Code Editor:

What is the difficulty level of this exercise?

Test your Programming skills with w3resource's quiz.

﻿