I have a list of varying length that I want to continuously up date with some new data. So basically I want to add a new data point and remove any data out of a set range. I have been playing around with this for a little bit now and haven't gotten anywhere that I can tell. I was trying to use this post as a reference, but apparently I don't under stand what is going on. Below is a code snippet that is an example of what I have tried.
for i in range(0,100):
n.append(i)
n = [x for x in n if not (x-n[-1]>10)]
print len(n)
Ideally n would only have the last 10 data points contained in it at any given time during the for loop. I am sure that this is something basic that I am just not understanding, if you all could help me out I would really appreciate it. Thanks.
Edit: Example of the list n
[0]
[0, 1]
...
[89, 90, 91, 92, 93, 94, 95, 96, 97, 99]