Find variable closest to a value in a list
Question: I have only programmed basic functions in python before, so I hope this is
clear.

I have a list of variables `[A1, A2, A3, A4, A5, A6, A7, A8, A9, A10]` to 1
decimal place. I have a variable B which can be any number to decimal place. I
would like to find the closest value in the list to variable B. And return not
the value but the A number(A5 for example).

Thanks!


Answer: 
    from operator import itemgetter
    
    a = [A1, A2, ........, A10]
    minimum_list = [abs(variable - B) for variable in a]
    
    return min(enumerate(minimum_list), key=itemgetter(1))[0]
    

This will return the index of the variable with the minimum difference.

    
    
    return a[min(enumerate(minimum_list), key=itemgetter(1))[0]]
    

This will return the value in the list with the minimum difference with the
variable B

