title: How to improve performance for large lists in python
body: <p>I have a large list with say 10 million of integers (sorted) "alist". What I need is to get the smallest distance between some of the integers (from a "blist") and the neighbours in the list. I do it by finding the position of the integer I look for, get the item before and after and measure the difference:</p>
  
  <pre><code>alist=[1, 4, 30, 1000, 2000] #~10 million integers
  blist=[4, 30, 1000] #~8 million integers
  
  for b in blist:
      position=alist.index(b)
      distance=min([b-alist[position-1],alist[position+1]-b])
  </code></pre>
  
  <p>This operation has to be repeated millions of times and, unfortunately, it takes ages on my machine. Is there a way to improve performance of this code? I use python 2.6 and python 3 is not an option.</p>