title: How to remove an element and append python list conditionally?
body: <p>I receive timeseries data from a broker and want to implement condition monitoring on this data. I want to analyze the data in a window of size 10. The window size must always stay the same. When the 11th data comes, I need to check its value against two thresholds which are calculated from the 10 values inside a window. If the 11th data is outsider, I must delete the data from the list and if it is within the range, I must delete the first element and add the 11th data to the last element. So this way the size of window stays the same. The code is simplified. <code>data</code> comes each 1 second.</p>
  <pre><code>temp_list = []
  window_size = 10
  
  if len(temy_list) &lt;= window_size :
      temp_list.append(data)
  if len(temp_list) == 10:
      avg = statistics.mean(temp_list)
      std = statistics.stdev(temp_list)
      u_thresh = avg + 3*std
      l_thresh = avg - 3*std
      temp_list.append(data)
      if temp_list[window_size] &lt; l_thresh or temp_list[window_size] &gt; u_thresh:
          temp_list.pop(-1)
  
      else:
          temp_list.pop(0)
          temp_list.append(data)
  </code></pre>
  <p>With this code the list does not get updated and 11th data is stored and then no new data. I don't know how to correctly implement it. Sorry, if it is a simple question. I am still not very comfortable with python list. Thank you for your hint/help.</p>