Featured Post

SQL Interview Success: Unlocking the Top 5 Frequently Asked Queries

Image
 Here are the five top commonly asked SQL queries in the interviews. These you can expect in Data Analyst, or, Data Engineer interviews. Top SQL Queries for Interviews 01. Joins The commonly asked question pertains to providing two tables, determining the number of rows that will return on various join types, and the resultant. Table1 -------- id ---- 1 1 2 3 Table2 -------- id ---- 1 3 1 NULL Output ------- Inner join --------------- 5 rows will return The result will be: =============== 1  1 1   1 1   1 1    1 3    3 02. Substring and Concat Here, we need to write an SQL query to make the upper case of the first letter and the small case of the remaining letter. Table1 ------ ename ===== raJu venKat kRIshna Solution: ========== SELECT CONCAT(UPPER(SUBSTRING(name, 1, 1)), LOWER(SUBSTRING(name, 2))) AS capitalized_name FROM Table1; 03. Case statement SQL Query ========= SELECT Code1, Code2,      CASE         WHEN Code1 = 'A' AND Code2 = 'AA' THEN "A" | "A

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

Explained Ideal Structure of Python Class

How to Check Kafka Available Brokers