What is the maximum size of a python list?

0 votes
107 views
asked Aug 6, 2016 by Hitesh Garg (251 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

0 votes
answered Sep 10, 2016 by sksanjai (35 points)  
selected Sep 10, 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.

Welcome to Codingeek Q&A, where you can ask questions and receive answers from other members of the community.
...