How to Find Max and Min Quickly in Python List

Here's logic to find Max and Min values in a List. Without using built-in Max() and Min () functions you can find Max and Min values in a List. For that matter, you need to write a user-defined function. This post is all about how to write it and run.

Finding Max and Min in List

You can achieve this by writing a user-defined function. Here's useful logic and steps to write it precisely.


  • Write a Function
  • Execute Function
  • Get the result
  • Write Function

You can write an user-defined function to get MAX and MIN values. In this function, I am using the max(), min() built-in functions. The other variables you can use as you wish. Below is the my actual logic.

Python Function to find Maximum and Minimum Easily

Sample Code

def findmaxmin(data): 
ax = max(data) 
by = min(data) 
data = (109, 98, 88, 7) 
(maximum, minimum) = findmaxmin (data) 
print("Maximum Marks = ", maximum) 
print("Minimum Marks = ", minimum)

Created a Script Using vim editor

Here as the first step, I have written the file in Ubuntu. The function name is  "findmaxmin ".

define function using input arguments


Below command to enter Python. This command, you can issue in Ubuntu where python3 is installed

$ python3

You have now entered Python3.

>>> import maxmin

You will prompt a message that imported successfully without any syntax errors.

Code in the Python Script

How to import python script and run

Below commands, I have issued.

>>> data = (109, 98, 88, 7)
>>> maxmin.findmaxmin(data)

The result is (109, 7)


Post a Comment

Thanks for your message. We will get back you.

Previous Post Next Post