List without negative indexing
<p>I am coding a simply discrete system in python which is presented bellow:</p>

<pre><code>class System:
  def __init__(self, a, b):
    self.a = a
    self.b = b
    self.y = []


  def dynamics(self, signal):
    for i in range(len(signal)):
      try:
         self.y.append(signal[i] - self.a*self.y[i-1] - self.b*self.y[i-2])
      except:
        try:
           self.y.append(signal[i] - self.a*self.y[i-1] - self.b*0)
        except:
           self.y.append(signal[i] - self.a*0 - self.b*0)
</code></pre>

<p>The class System aims to model the system and the method dynamics to compute the dynamic system evolution through discrete time. I thought that  would be a good idea to use the try/except structure to deal with the first steps of the system - in our case the first two steps - in each some previous values of y would be not available. Well, this approach would work, if the list object does not accepted negative index, which is not the case. I know that I could solve this problem with other implementation approaches but, I would like to keep with this one. So, this is my question, how could I create a list object and disable negative indexing.  I would appreciate some chunks of code.</p>

<p>Thanks</p>

<p>Although I pointed out my reluctance in the comments, I'll play your game.</p>

<pre><code>class PositiveList(list):

    def __getitem__(self, ind):
        if ind &lt; 0:
            raise IndexError("Expected a positive index, instead got {}.".format(ind))
        return super(PositiveList, self).__getitem__(ind)

x = PositiveList([1, 2, 3])
print x[-1]
#IndexError: Expected a positive index, instead got -1.
</code></pre>

python list wrap