In: Computer Science
how to write a code with python function trying to find minimum difference between any two elements in a list
/*If you any query do comment in the comment section else like the solution*/
def getListDiff(li1, li2):
li_dif = [i for i in li1 + li2 if i not in li1 or i not in li2]
return li_dif
li1 = []
li2 = []
num1 = int(input("Enter number of elements in list 1: "))
print("Enter {} elements for list 1: ".format(num1))
str1 = input()
strsplit1 = str1.split(" ")
for i in range (0, num1):
x = int(strsplit1[i])
li1.append(x)
num2 = int(input("Enter number of elements in list 2: "))
print("Enter {} elements for list 2: ".format(num2))
str2 = input()
strsplit2 = str2.split(" ")
for i in range (0, num2):
x = int(strsplit2[i])
li2.append(x)
li3 = getListDiff(li1, li2)
print(li3)
Output: