vendredi 14 février 2020

Compare values in two lists and return the similar or nearest value from a third list

I will like to find similar values of j in v and return x. when the value in j is not equal to v, I will like the code the detect the 2 value in v that j values between. so if j falls between v1 and v2, I will like the code to return max(x1,x2)- ( ((j-v1)/(v2-v1))*(max(x1,x2)-min(x1,x2)))

v= [100,200,300,400,500,600,700,800,900,1000,1100]
x= [67,56,89,21,90,54,38,93,46,17,75]
j= [200,300,400,460,500,600,700,800,870,900,950]

for i in range(len(v)-1):
    if v[i] > j and V[i+1] < j:
        p = max(x[i],x[i+1])- ( ((j-v[i])/(v[i+1]-v[i]))*(max(x[i],x[i+1])-min(x[i],x[i+1])))
    elif v[i] ==j:
        b= x[i]
print(p,b)

"""
n = [x[i] for i, v_ele in enumerate(v) if v_ele in j]
p=  [x[i] for i, v_ele in enumerate(v) if v_ele > j and v_ele 
print(n)
"""

I will like my answers to return

[56,89,21,48.6,90,54,38,93,60.1,46,31.5]

Aucun commentaire:

Enregistrer un commentaire