Cody Bable

Generation

generate functionTue, 23 May 2023

given a set of integers and a value for which you need to find the nearest one.

def nearest_val(nums, val): diff = [abs(val-i) for i in nums] min_diff = min(diff) return diff.index(min_diff) nearest_val([1,2,3,4,5], 10)

Want to kickstart your project?Use the new AI Studio to create your code