Sep-02-2017, 02:04 PM
math.isclose() can be helpful. It also lets you define the degree of approximation(relative and absolute tolerance).
But if you want to find the closest match in a list of the number then you can use:
(Sep-02-2017, 01:02 PM)ankur2207 Wrote: So I have a column of integer values and generating random number. Now I need to find an exact or approximate match of that Random Number.
But if you want to find the closest match in a list of the number then you can use:
closest = min(random_list, key=lambda x:abs(x-random_num))