To get the minimum absolute difference between the two lists by using Python.
In this tutorial we will print the minimum absolute difference of two lists by creating a function in Python.
Hello Everyone, In this tutorial, we will learn how to get the maximum absolute difference between the two lists using Python.
Absolute difference: If there are two real numbers x and y, then the absolute difference between them is |x-y|
In this tutorial, we will find the lists and the maximum absolute difference between the list
For example : l1= [1,2,3] and l2=[9,8,7]
so the absolute difference above is |1-9| is 8; similarly |2-8| is 6, and |3-7| is 4
So, according to our problem is like to get the maximum difference is 8
So let us see this in Python.
def sub(l1,l2):
s=[]
for i in range(0,len(l1)):
d=l1[i]
p=l2[i]
s.append(abs(d-p))
return min(s)
l1=eval(input())
l2=eval(input())
print("minimum absolute difference between the lists is = ",sub(l1,l2))
Here I have created the function called sub, and inside I gave the parameters like l1 and l2. These are the lists taken from the user
s is an empty list that holds the absolute difference between each element in the list
And by using the for loop, we are iterating through the lists
d and p are the variables that hold the number for respective indexing
Now appending the difference between the d and p
After complete executing the for loop statement then by using the return statement, we will return the minimum element of s by using the min function
output:
1,2,3 4,5,6 minimum absolute difference between the lists is = 3
here the 1,2,3 are the elements that are in list1
and 4,5,6 are the elements that are in list2
Project Files
| .. | ||
| This directory is empty. | ||