def knn_classify(k, labeled_points, new_point):
 by_distance = sorted(labeled_points, key=(lambda (point, _): distance(point, new_point)))
 k_nearest_labels = [label for (_, label) in by_distance[:k]]
 return majority_vote(k_nearest_labels)

def knn_classify ( k , labeled_points , new_point ) : by_distance = sorted ( labeled_points , key = ( lambda ( point , _ ) : distance ( point , new_point ) ) ) k_nearest_labels = [ label for ( _ , label ) in by_distance [ : k ] ] return majority_vote ( k_nearest_labels )
each labeled point should be a pair .