Python – Find Minimum of Items in a Tuple
To find minimum of items in a Tuple in Python, use min() builtin function. We can also provide a key function for min() to transform the items and then find the minimum of those values.
Examples
1. Minimum of Tuple of Integers
In the following program, we take a tuple x
with integer values, and find the minimum item in this tuple.
Python Program
</>
Copy
aTuple = (2, 5, 8, 1, 4, 3)
result = min(aTuple)
print('Minimum :', result)
Output
Minimum : 1
2. Minimum of Tuple of Strings based on Length
Here key is length of the item. To find minimum of strings based on length, call min() function and send len() function as key parameter.
Python Program
</>
Copy
aTuple = ('Tea', 'Banana', 'Pomegranate')
result = min(aTuple, key=len)
print('Minimum :', result)
Output
Minimum : Tea
Conclusion
In this Python Tutorial, we learned how to find the minimum of items in a Tuple in Python using min() function.