Python | Maximum and Minimum in a Set

In this article, we will learn how to get the maximum and minimum element in a set in Python, using the built-in functions of Python.
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 a Set



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

filter_none

edit
close

play_arrow

link
brightness_4
code

# Python code to get the maximum element from a set
def MAX(sets):
    return (max(sets))
      
# Driver Code
sets = set([8, 16, 24, 1, 25, 3, 10, 65, 55])
print(MAX(sets))

chevron_right


Output:

65

min() in a Set

filter_none

edit
close

play_arrow

link
brightness_4
code

# Python code to get the minimum element from a set
def MIN(sets):
    return (min(sets))
      
# Driver Code
sets = set([4, 12, 10, 9, 4, 13])
print(MIN(sets))

chevron_right


Output:

4


My Personal Notes arrow_drop_up

Check out this Author's contributed articles.

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.




Article Tags :
Practice Tags :


1


Please write to us at contribute@geeksforgeeks.org to report any issue with the above content.