Python | Minimum element in tuple list
Sometimes, while working with data in form of records, we can have a problem in which we need to find the minimum element of all the records received. This is a very common application that can occur in Data Science domain. Let’s discuss certain ways in which this task can be performed.
Method #1 : Using min() + generator expression
This is the most basic method to achieve solution to this task. In this, we iterate over whole nested lists using generator expression and get the minimum element using min().
# Python3 code to demonstrate working of # Minimum element in tuple list # using min() + generator expression # initialize list test_list = [(2, 4), (6, 7), (5, 1), (6, 10), (8, 7)] # printing original list print("The original list : " + str(test_list)) # Minimum element in tuple list # using min() + generator expression res = min(int(j) for i in test_list for j in i) # printing result print("The Minimum element of list is : " + str(res)) |
The original list : [(2, 4), (6, 7), (5, 1), (6, 10), (8, 7)] The Minimum element of list is : 1
Method #2 : Using min() + map() + chain.from_iterable()
The combination of above methods can also be used to perform this task. In this, the extension of finding minimum is done by combination of map() and from_iterable().
# Python3 code to demonstrate working of # Minimum element in tuple list # using min() + map() + chain.from_iterable() from itertools import chain # initialize list test_list = [(2, 4), (6, 7), (5, 1), (6, 10), (8, 7)] # printing original list print("The original list : " + str(test_list)) # Minimum element in tuple list # using min() + map() + chain.from_iterable() res = min(map(int, chain.from_iterable(test_list))) # printing result print("The Minimum element of list is : " + str(res)) |
The original list : [(2, 4), (6, 7), (5, 1), (6, 10), (8, 7)] The Minimum element of list is : 1
Recommended Posts:
- Python | Sort tuple list by Nth element of tuple
- Python | Maximum element in tuple list
- Python | Remove particular element from tuple list
- Python | Update each element in tuple list
- Python | Count the elements in a list until an element is a Tuple
- Python | Remove duplicates based on Kth element tuple list
- Python | Replace tuple according to Nth tuple element
- Python | Maximum and minimum element's position in a list
- Python | Convert mixed data types tuple list to string list
- Python program to create a list of tuples from given list having number and its cube in each tuple
- Python | Merge list of tuple into list by joining the strings
- Python | Pair and combine nested list to tuple list
- Python | Convert list to indexed tuple list
- Python | Convert Integral list to tuple list
- Python | Counting Nth tuple element
If you like GeeksforGeeks and would like to contribute, you can also write an article using contribute.geeksforgeeks.org or mail your article to contribute@geeksforgeeks.org. See your article appearing on the GeeksforGeeks main page and help other Geeks.
Please Improve this article if you find anything incorrect by clicking on the "Improve Article" button below.

