What is the maximum size of a python list?

0 votes
asked Aug 6, 2016 by Hitesh Garg (799 points)  

I have to read a file and create objects which will finally be saved in a list. Size of file is not determined as of now but it is believed to have objects in millions.

So what is the size that a list can extend to without causing any trouble?

1 Answer

+1 vote
answered Sep 9, 2016 by sksanjai (45 points)  
selected Sep 9, 2016 by Hitesh Garg
Best answer

According to the source code, the maximum size of a list is PY_SSIZE_T_MAX/sizeof(PyObject*) . PY_SSIZE_T_MAX is defined in pyport.h to be ((size_t) -1)>>1.
On a regular 32bit system, this is (4294967295 / 2) / 4 or 536870912. Therefore the maximum size of a python list on a 32 bit system is 536,870,912 elements.