The Wayback Machine - https://web.archive.org/web/20241005021413/https://www.geeksforgeeks.org/python-maximum-minimum-set/
Open In App

Python | Maximum and Minimum in a Set

Last Updated : 24 Feb, 2023
Summarize
Comments
Improve
Suggest changes
Like Article
Like
Save
Share
Report
News Follow

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. 

Python3




# 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))


Output:

65

min() in a Set

Python3




# 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))


Output:

4

Time complexity: O(n)
Auxiliary space: O(n), n is number of elements in set.


Previous Article
Next Article

Similar Reads

How to Get the Minimum and maximum Value of a Column of a MySQL Table Using Python?
Prerequisite: Python: MySQL Create Table In this article, we are going to see how to get the Minimum and Maximum Value of a Column of a MySQL Table Using Python. Python allows the integration of a wide range of database servers with applications. A database interface is required to access a database from Python. MySQL Connector-Python module is an
2 min read
Python | Maximum and minimum element's position in a list
Given a list of N integers, find the maximum and minimum element's position in the Python list. Example Input: 3, 4, 1, 3, 4, 5Output: The maximum is at position 6 The minimum is at position 3Maximum and Minimum Element Position in a ListBelow are the methods and ways by which we can find minimum and maximum element position in a Python List: Using
3 min read
Return the maximum of an array along axis 0 or maximum ignoring any NaNs in Python
In this article, we will see how to return the maximum of an array along axis 0 or maximum ignoring any NaNs in Python. ExampleInput: [[ 1. 0. 3.] [10. nan 30.] [nan 10. 20.]] Output: [10. 10. 30.] Explanation: An array with maximum values.nanmax method in PythonPython provides a nanmax method that returns the maximum of an array along a specified
3 min read
Return the maximum of an array or maximum ignoring any NaNs in Python
In this article, we will cover how to return the maximum of an array or maximum by ignoring any NaNs in Python using NumPy. ExampleInput: [ -1. -2. nan 1000.] Output: 1000.0 Explanation: maximum value of the array ignoring nans. One approach to use the built-in Python function max(), along with the filter() function and the math.isnan() function fr
4 min read
Select row with maximum and minimum value in Pandas dataframe
Let's see how can we select rows with maximum and minimum values in Pandas Dataframe with help of different examples using Python. Creating a Dataframe to select rows with max and min values in Dataframe C/C++ Code # importing pandas and numpy import pandas as pd import numpy as np # data of 2018 drivers world championship dict1 = {'Driver': ['Hami
2 min read
Calculate the difference between the maximum and the minimum values of a given NumPy array along the second axis
Let's see how to calculate the difference between the maximum and the minimum values of a given NumPy array along the second axis. Here, the Second axis means row-wise. So firstly for finding the row-wise maximum and minimum elements in a NumPy array we are using numpy.amax() and numpy.amin() functions of NumPy library respectively. then After that
2 min read
Find the maximum and minimum element in a NumPy array
An array can be considered as a container with the same types of elements. Python has its array module named array. We can simply import the module and create our array. But this module has some of its drawbacks. The main disadvantage is we can't create a multidimensional array. And the data type must be the same. To overcome these problems we use
4 min read
How to find the maximum and minimum value in NumPy 1d-array?
Let's see the various ways to find the maximum and minimum value in NumPy 1d-array. Method 1: Using numpy.amax() and numpy.amin() functions of NumPy library. numpy.amax(): This function returns maximum of an array or maximum along axis(if mentioned). numpy.amin(): This function returns minimum of an array or minimum along axis(if mentioned). Exampl
2 min read
Find Minimum, Maximum, and Average Value of PySpark Dataframe column
In this article, we are going to find the Maximum, Minimum, and Average of particular column in PySpark dataframe. For this, we will use agg() function. This function Compute aggregates and returns the result as DataFrame. Syntax: dataframe.agg({'column_name': 'avg/'max/min}) Where, dataframe is the input dataframecolumn_name is the column in the d
2 min read
Maximum length prefix such that frequency of each character is atmost number of characters with minimum frequency
Given a string S, the task is to find the prefix of string S with the maximum possible length such that frequency of each character in the prefix is at most the number of characters in S with minimum frequency. Examples: Input: S = 'aabcdaab' Output: aabcd Explanation: Frequency of characters in the given string - {a: 4, b: 2, c: 1, d: 1} Minimum f
8 min read
PyQtGraph – Getting Maximum/Minimum Size of Image View
In this article, we will see how we can get the maximum/minimum size of the image view in PyQTGraph. PyQtGraph is a graphics and user interface library for Python that provides functionality commonly required in designing and science applications. Its primary goals are to provide fast, interactive graphics for displaying data (plots, video, etc.).
4 min read
Minimum Cost Maximum Flow from a Graph using Bellman Ford Algorithm
Given a source node S, a sink node T, two matrices Cap[ ][ ] and Cost[ ][ ] representing a graph, where Cap[i][j] is the capacity of a directed edge from node i to node j and cost[i][j] is the cost of sending one unit of flow along a directed edge from node i to node j, the task is to find a flow with the minimum-cost maximum-flow possible from the
15+ min read
PyQt5 – Set minimum window size | setMinimumWidth and setMinimumHeight method
When we create a window, by default the window size is resizable although, we can use setMinimumSize() method to set the minimum size of the window. But what if we want to set minimum length only for width or height only, in order to do so we use setMinimumWidth() method to set minimum width and setMinimumHeight() method to set minimum height. When
2 min read
PyQt5 – Set maximum size for width or height of window
When we create a window, by default the window size is resizable, although we can use setMaximumSize() method to set the maximum size of the window. But what if we want to set maximum length only for width or height only. In order to do so we use setMaximumWidth() and setMaximumHeight() method to set maximum width / height. When we use these method
2 min read
PyQt5 – Set maximum window size
When we create a window, by default, it is resizable but with the help of setFixedSize() method we can fix the size of window. But what if we want to resize the window up-to some extent; in order to do this, we have to set the maximum size of the window. We will use setMaximumSize() method. Syntax : self.setMaximumSize(width, height) Argument : It
1 min read
PyQt5 - Set maximum size of status bar
We know by default when we resize the window, status bar also get resized. In this article we will see how to set the maximum size of the status bar i.e when we extend the window status bar should not extend beyond this size. In order to do this we will use setMaximumSize method with status bar object. Syntax : self.statusBar().setMaximumSize(width
2 min read
PyQt5 - How to set the maximum value of progress bar ?
In this article we will see how to set the maximum value of progress bar. By default the maximum value of progress bar is 100, but we can change it to our need. In order to do this we will use setMaximum method, this will change the maximum value of progress bar. Note : When we will set the value to progress bar using setValue method, the percentag
2 min read
PyQt5 QDateEdit - Removing Maximum Date Time which can be set
In this article we will see how we can remove the maximum date time of the QDateEdit. Sometimes there is a need to set maximum date time so that user can't enter date time which are beyond the maximum date time. We can set date time to date edit with the help of setDateTime method. Maximum date-time can be set with the help of setMaximumDateTime me
2 min read
PyQt5 QDateEdit - Setting Maximum Date Time which can be set
In this article we will see how we can set maximum date time to the QDateEdit. Sometime there is a need to set maximum date time so that user can't enter date time which are beyond the maximum date time. We can set date time to date edit with the help of setDateTime method. In order to do this we use setMaximumDateTime method with the QDateEdit obj
2 min read
PyQt5 QDateEdit - Getting Maximum Date Time which can be set
In this article we will see how we can get maximum date-time of the QDateEdit. Sometimes there is a need to set maximum date time so that user can't enter date time which are beyond the maximum date time. We can set date time to date edit with the help of setDateTime method. Maximum date-time can be set with the help of setMaximumDateTime method. I
2 min read
PyQt5 QDateEdit - Setting Maximum Time which can be set
In this article we will see how we can set maximum time to the QDateEdit. Sometimes there is a need to set maximum time so that user can't enter/store time which are beyond the maximum time. We can set time to date edit with the help of setTime method. In order to do this we use setMaximumTime method with the QDateEdit object Syntax : date.setMaxim
2 min read
PyQt5 QDateEdit - Removing Maximum Time which can be set
In this article we will see how we can remove maximum time to the QDateEdit. Sometimes there is a need to set maximum time so that user can't enter/store time which are beyond the maximum time. We can set time to date edit with the help of setTime method. We can set the maximum time to it with the help of setMaximumTime method. In order to do this
2 min read
PyQt5 QDateEdit - Getting Maximum Time which can be set
In this article we will see how we can get maximum time to the QDateEdit. Sometimes there is a need to set maximum time so that user can't enter/store time which are beyond the maximum time. We can set time to date edit with the help of setTime method. We can set the maximum time to it with the help of setMaximumTime method. In order to do this we
2 min read
PyQt5 – How to set minimum size of window | setMinimumSize method
We know that we can resize the window of PyQt5 application, but while shrinking the window size we can set minimum size so that it can't be shrank any more. In this article, we will see how to do this. In order to do this we will use setMinimumSize() method. Syntax : self.setMinimumSize(width, height) Argument : It takes two integer as argument. Ac
1 min read
PyQt5 – Set minimum size of Status Bar
We know that we can resize the window of PyQt5 application but when we resize the window, status bar also get resized according to the size of window. While shrinking the window size we can set minimum size so that status bar can’t be shrank any more. In this article, we will see how to do this, in order to do this we will use setMinimumSize() meth
2 min read
PyQt5 – Set minimum length for width/height of Status Bar
When we create a status bar, by default, the status bar size is resizable. Although we can use setMinimumSize() method with status bar to set the minimum size of the status bar but what if we want to set minimum length for width or height only. In order to do, so we use setMinimumWidth() method with status bar to set minimum width and setMinimumHei
2 min read
PyQt5 - How to set minimum value of progress bar ?
In this article we will see how to set the minimum value of progress bar. By default the minimum value of progress bar is 0, but we can change it to our need. In order to do this we will use setMinimum method, this will change the maximum value of progress bar. If we change the minimum value, percentage will change accordingly percentage = ((value_
2 min read
PyQt5 - Set minimum content length to ComboBox item
In this article we will see how we can set the minimum length to the items of combo box i.e this property holds the minimum number of characters that should fit into the combo box. In order to do this we will use setMinimumContentsLength method, by default minimum length of combo box is 0. Syntax : combo_box.setMinimumContentsLength(n) Argument : I
2 min read
PyQt5 QDateEdit - Removing Minimum Time which can be set
In this article we will see how we can remove minimum time of the QDateEdit. Sometimes there is a need to set minimum time so that user can't enter/store time which are beyond the minimum time. We can set time to date edit with the help of setTime method. Minimum time can be set to the date edit with the help of setMinimumTime method. In order to d
2 min read
PyQt5 QDateEdit - Getting Minimum Date Time which can be set
In this article we will see how we can get the minimum date-time of the QDateEdit. Sometimes there is a need to set minimum date time so that user can't enter date time which are beyond the minimum date time. We can set date time to date edit with the help of setDateTime method. Minimum date-time can be set to the date edit with the help of setMini
2 min read
Article Tags :
Practice Tags :