memory allocation for Python list

dmitrey dmitrey.kroshko at scipy.org
Wed Mar 26 08:50:15 EDT 2008


hi all,
I have a python list of unknown length, that sequentially grows up via
adding single elements.
Each element has same size in memory (numpy.array of shape 1 x N, N is
known from the very beginning).
As I have mentioned, I don't know final length of the list, but
usually I know a good approximation, for example 400.

So, how can I optimize a code for the sake of calculations speedup?
Currently I just use

myList = []

for i in some_range:
    ...
    myList.append(element)
    ...

Thank you in advance,
Dmitrey




More information about the Python-list mailing list