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>This does what you actually want and is much cleaner. Just keep the latest two y-values in extra variables.</p>

<pre><code>def dynamics(self, signal):
    y1 = y2 = 0
    for sig in signal:
        y1, y2 = sig - self.a * y1 - self.b * y2, y1
        self.y.append(y1)
</code></pre>

python list wrap