Here is my code to get the nearest value to a given number ( Mynumber) from a list (Mylist)
Mylist= [ 1, 2, 3]
Mynumber=3
takeClosest = lambda num,collection:min(collection,key=lambda x:abs(x-
num))
closest= [takeClosest(Mynumber,Mylist)]
print closest
Now I have 3 lists [ 1, 2, 3] ,[ 4, 7, 8], [ 13, 9, 10] I want to compare first item , second item and 3rd item of them with this list,[2,6,9] ,If I compare 1st item in each list, out if [1,4,13], 1 is the closest to 2 ,If I compare 2nd item in each list, out of [2,7,9], 7 is the closest to 6,If I compare 3rd item in each list, out of [3,8,10], 10 is the closest to 9 Does any one know how to do it? Any suggestion would be greatly appreciated
"""
Mylist1= [ 1, 2, 3]
Mylist2= [ 4, 7, 8]
Mylist3= [ 13, 9, 10]
Mynumber=[2,6,9]
"""