title: Round each number of list to most near number in another list
body: <p>Suppose I have a certain list <code>x</code> with numbers, and another list <code>y</code> with other numbers. Elements of <code>y</code> should be elements of <code>x</code>, but due to noise in measurements, they are kind of different. I want to find, for each value of <code>y</code>, the value of <code>x</code> that is the nearest to it.</p>
  
  <p>I can do this with some loops and check, for each element <code>y[i]</code>, which element <code>x[j]</code> minimizes <code>abs(x[j]-y[i])</code>, but I'm pretty sure there is a much easier, cleaner way to do this. The lists could be huge so I'm looking for efficient code here.</p>
  
  <p>The code I've written so far is:</p>
  
  <pre><code>x_in = [1.1, 2.2, 3, 4, 6.2]
  y_in = [0.9, 2, 1.9, 6, 5, 6, 6.2, 0.5, 0, 3.1]
  desired_output = [1.1, 2.2, 2.2, 6.2, 4, 6.2, 6.2, 1.1, 1.1, 3]
  
  y_out = []
  
  for y in y_in:
      aux = [abs(l - y) for l in x_in]
      mn,idx = min( (aux[i],i) for i in range(len(aux)) )
      y_out.append(x_in[idx])
  
  &gt;&gt;&gt; y_out == desired_output
  True
  </code></pre>
  
  <p>But I don't know if there is a more efficient way to do this...</p>
  
  <p>EDIT:</p>
  
  <p>Due to my ignorance, I forgot to clarify something that may be of relevance according to the comments I've recieved.</p>
  
  <ul>
  <li>The <code>x</code> list is sorted.</li>
  <li><code>x</code> is the only list that can have a pretty big size: between 500,000 and 1,000,000 elements, in general. <code>y</code> will in general be really small, less than 10 elements.</li>
  </ul>