Python list Limit

Fredrik Lundh fredrik at pythonware.com
Fri Nov 17 10:34:32 EST 2006


Bugra Cakir wrote:

> What is the size limit of list data type in Python ?

there is no limit, beyond the size of a pointer, and the limitations put on your
program by the operating system.

> I've found an MemoryError while extending a list with
>
> samplelist.extend("tail")

when the list is resized, you need to be able to hold an extra copy of the list in
memory simultaneously, in worst case.  the size of a list depends on the number
of items in it, not the size of the actual items, so the peak memory use for a list
of size "size" is a little over 2*size*sizeof(pointer).

are you adding stuff to multiple large lists simultaneously?  have you plotted the
memory growth and compared it to the list size growth?  if memory growth is
more quadratic than linear, you're probably fragmenting the memory.  the only
solution to that problem is to use a better data structure.

</F> 






More information about the Python-list mailing list