C
charles.hebert
Hi,
Can anybody tell me how to to find the nearest value to zero in a list
?
To do that, i'm using list comprenhension :
Something simpler ?
How to extend this function to any given value ?
Thanks,
CH.
Can anybody tell me how to to find the nearest value to zero in a list
?
To do that, i'm using list comprenhension :
[-1]foo = [-5,-1,2,3] # nearest value to zero ?
[value for value in foo if math.fabs(value) == min([int(math.fabs(x)) for x in foo])]
Something simpler ?
How to extend this function to any given value ?
Thanks,
CH.