How Big can a Python List Get?
How Big can a Python List Get?
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.
As long as the number of elements you have is equal or below this, all list functions should operate correctly.
As the Python documentation says:
sys.maxsize
The largest positive integer supported by the platform’s Py_ssize_t type, and thus the maximum size lists, strings, dicts, and many other containers can have.
In my computer (Linux x86_64):
>>> import sys
>>> print sys.maxsize
9223372036854775807
How Big can a Python List Get?
Sure it is OK. Actually you can see for yourself easily:
l = range(12000)
l = sorted(l, reverse=True)
Running the those lines on my machine took:
real 0m0.036s
user 0m0.024s
sys 0m0.004s
But sure as everyone else said. The larger the array the slower the operations will be.