Skip to content

Instantly share code, notes, and snippets.

Last active Jan 16, 2017
What would you like to do?
def UpdateNeighbors(neighbors,item,distance,k):
if(len(neighbors) < k):
#List is not full, add new item and sort
neighbors = sorted(neighbors);
#List is full
#Check if new item should be added
if(neighbors[-1][0] > distance):
#If yes, replace the last element with new item
neighbors[-1] = [distance,item["Class"]];
neighbors = sorted(neighbors);
return neighbors;
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment