title: Data structure for custom indexing
body: <p>I am looking to write a data structure to represent some genetic data. This data can be represented as a list of size <code>n</code>, where each entry also has a "genetic position" which is a real number between 0 and 1. To make nomenclature clear, I'll call the position in the list <code>id</code> and the genetic position <code>gpos</code>. The way I implemented this is as a class with </p>
  
  <pre><code>class Coords(object):
  
      def __init__(self, *args, **kwargs):
          self.f = list(*args, **kwargs)
          self.r = dict()
          for i,e in enumerate(self.f):
              self.r[e] = i
  
      def __setitem__(self,x,y):
          self.f.__setitem__(x,y)
          self.r.__setitem__(y,x)
  
      def __getitem__(self,x):
          return self.f.__getitem__(x)
  
      def __len__(self):
          return self.f.__len__()
  </code></pre>
  
  <p>now, I have two issues with this. The first one is that the indeces of self.r are floats, which is obviously a bad idea. I was thinking of converting them to strings (with a fixed number of digits), but is there a better idea? The other issue I have is that I want to implement accessing entries via <code>gpos</code>, so if I, for example, would like to access everything between <code>gpos</code> 0.2 and 0.4, I would like to be able to do that using</p>
  
  <pre><code>import numpy as np
  Coords(np.arange(1,0,-.1))
  c.r[0.2:0.4]
  </code></pre>
  
  <p>is there an easy way to define that? I was thinking of finding the correct <code>id</code> of the starting and ending positions using binary search and then access <code>self.f</code> using these ids, but is there a way to implement above syntax?</p>