
Data Structure
Networking
RDBMS
Operating System
Java
MS Excel
iOS
HTML
CSS
Android
Python
C Programming
C++
C#
MongoDB
MySQL
Javascript
PHP
- Selected Reading
- UPSC IAS Exams Notes
- Developer's Best Practices
- Questions and Answers
- Effective Resume Writing
- HR Interview Questions
- Computer Glossary
- Who is Who
Index of Minimum Value Record in Python
If it is required to find the tuple corresponding to the minimum value of other tuple index, it can be done using the 'min' method, and the 'operator.itemgetter' method.
The 'min' method gives the minimum of the elements in the iterable. The itemgetter fetches a specific item from its operand.
Below is a demonstration of the same −
Example
from operator import itemgetter my_list = [('Will', 45), ('Jam', 13), ('Pow', 89), ('Nyk', 56)] print ("The list is: " ) print(my_list) my_result = min(my_list, key = itemgetter(1))[0] print ("The value with minimum score is : " ) print(my_result)
Output
The list is: [('Will', 45), ('Jam', 13), ('Pow', 89), ('Nyk', 56)] The value with minimum score is : Jam
Explanation
- The required packages are imported.
- A list of tuples is defined, and is displayed on the console.
- The 'min' function is applied on this list of tuples, with the key as the itemgetter.
- This itemgetter helps fetch a specific item from the operand.
- This value is assigned to a variable.
- This variable is the output, which is displayed on the console.
Advertisements