Say I have a list [1,2,3,4,5,6,7]. I want to find the 3 closest numbers to, say, 6.5. Then the returned value would be [5,6,7].
Finding one
You could compute distances, and sort:
[n for d, n in sorted((abs(x-myNumber), x) for x in myList)[:k]]
This does the following:
(d, x) where d is the distance to your targetk elements of that list