Store the newest 100 numbers. (delete old ones) The task is to store the newest ~100 numbers and calculate their sum.

I would like to optimize for time-performance.

Usage: In the context of sequence alignment, after creating a 2D scoring-matrix between 2 sequences, starting at the bottom right corner, I want to search for the optimal alignment path. Here I adapt previous alignment algorithms to search for the optimal alignment at a fixed alignment length. For this, the sum of the previous path isn't sufficient, but instead I want to save the values of the previous path into each cell. 

storage = []
new_number = 1

def store_numbers(storage, new_number, storage_size = 100):
    storage.append(new_number)
    if len(storage)&gt;storage_size:
        del storage[0]
    return storage, sum(storage)


#test
for x in range(100):
    print(store_numbers(storage, x, storage_size = 10)


Ideas: Avoid the function? Avoid append() - del() and instead overwrite? Instead of list use Numpy array or something else?
You could make your life way easier if you used the deque data structure.

from collections import deque

d = deque(maxlen=2)
d.append(1)
d.append(2)
d.append(3)

sum(d)  # gives 5, which is the sum of the last two inserted elements.


With this, you call the sum function only when you really need to, which will improve your performance if you don't need the sum every time (like when you're first populating the container).

Also, deque probably has faster length checking internally than using len onto a list.