Python | Maximum and minimum in the set

Python Methods and Functions

In this article, we will learn how to get the maximum and minimum element in a set in Python using built-in Python functions. 
Examples:

 Input: set = ([8, 16, 24, 1, 25, 3, 10, 65, 55]) Output: max is 65 Input: set = ([4 , 12, 10, 9, 4, 13]) Output: min is 4 

max () in the set

Python's built-in max () function is used to get the maximum of all elements in a set.

# Python code to get the maximum element from the set

def MAX (sets):

return ( max (sets))

 
Driver code

sets = set < code class = "plain"> ([ 8 , 16 , 24 , 1 , 25 , 3 , 10 , 65 , 55 ])

print ( MAX (sets))

Exit:

 65 

min () in the set

# Python code to get minimum element from the set 

def MIN (sets):

return ( min (sets))

 
Driver code

sets = set ([ 4 , 12 , 10 , 9 , 4 , 13 ])

print ( MIN (sets ))

Output:

 4 




Tutorials