Featured Post

14 Top Data Pipeline Key Terms Explained

Image
 Here are some key terms commonly used in data pipelines 1. Data Sources Definition: Points where data originates (e.g., databases, APIs, files, IoT devices). Examples: Relational databases (PostgreSQL, MySQL), APIs, cloud storage (S3), streaming data (Kafka), and on-premise systems. 2. Data Ingestion Definition: The process of importing or collecting raw data from various sources into a system for processing or storage. Methods: Batch ingestion, real-time/streaming ingestion. 3. Data Transformation Definition: Modifying, cleaning, or enriching data to make it usable for analysis or storage. Examples: Data cleaning (removing duplicates, fixing missing values). Data enrichment (joining with other data sources). ETL (Extract, Transform, Load). ELT (Extract, Load, Transform). 4. Data Storage Definition: Locations where data is stored after ingestion and transformation. Types: Data Lakes: Store raw, unstructured, or semi-structured data (e.g., S3, Azure Data Lake). Data Warehous...

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.


IN THIS PAGE

  • 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) 
return(x,y)
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 maxmin.py file in Ubuntu. The function name is  "findmaxmin ".

define function using input arguments

Result


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)


References

Comments

Popular posts from this blog

How to Fix datetime Import Error in Python Quickly

SQL Query: 3 Methods for Calculating Cumulative SUM

Big Data: Top Cloud Computing Interview Questions (1 of 4)