title: Comparing multidimensional lists and return the intersected index
body: <p>I try to write and edit a code based on some example from the <a href="https://machinelearningmastery.com/tutorial-to-implement-k-nearest-neighbors-in-python-from-scratch/" rel="nofollow noreferrer">internet</a> that goes like this:</p>
  
  <pre><code>from math import sqrt
  
  # calculate the Euclidean distance between two vectors
  def euclidean_distance(row1, row2):
      distance = 0.0
      for i in range(len(row1)-1):
          distance += (row1[i] - row2[i])**2
      return sqrt(distance)
  
  # Locate the clostest neighbors
  def get_neighbors(train, test_row, num_neighbors):
      distances = list()
      for train_row in train:
          dist = euclidean_distance(test_row, train_row)
          distances.append((train_row, dist))
      distances.sort(key=lambda tup: tup[1])
      neighbors = list()
      for i in range(num_neighbors):
          neighbors.append(distances[i][0])
      return neighbors
  
  # Test distance function
  dataset = [[2.7810836,2.550537003,0],
      [1.465489372,2.362125076,0],
      [3.396561688,4.400293529,0],
      [1.38807019,1.850220317,0],
      [3.06407232,3.005305973,0],
      [7.627531214,2.759262235,1],
      [5.332441248,2.088626775,1],
      [6.922596716,1.77106367,1],
      [8.675418651,-0.242068655,1],
      [7.673756466,3.508563011,1]]
  neighbors = get_neighbors(dataset, dataset[0], 3)
  
  #set(dataset) &amp; set(neighbors)
  
  #type(neighbors) is int
  #set(dataset).intersection(neighbors)
  
  for neighbor in neighbors:
      print(neighbor)
  </code></pre>
  
  <p>What I want to do is:</p>
  
  <ol>
  <li>Getting the 3 nearest neighbors,</li>
  <li>Comparing those  nearest neighbors to the 'dataset',</li>
  <li>Return the index of data point that matches.</li>
  </ol>
  
  <p>For example:
  from the code above, the result is:</p>
  
  <pre><code>[2.7810836, 2.550537003, 0]
  [3.06407232, 3.005305973, 0]
  [1.465489372, 2.362125076, 0]
  </code></pre>
  
  <p>The end result that I would like to have is:</p>
  
  <p>result = [1, 5, 2]</p>
  
  <p>which is the dataset index of the nearest 3 neighbors from the selected data point (including itself) assuming that the data index is starting from 1 not 0.</p>