Python Find Nearest Neighbors Algorithm