DEV Community

Discussion on: Challenge: Get Closest Number in an Array

Collapse
 
pbouillon profile image
Pierre Bouillon • Edited

Here goes Python !

min(nums, key=lambda x: abs(x - given_num))