Closest elements in a target array for a given input array (Python recipe) by Gerry Wiener ActiveState ...
code.activestate.com