Python列表可以有多大? [英] How Big can a Python List Get?
问题描述
在Python中,列表可以有多大?我需要大约12000个元素的列表.我仍然可以运行诸如排序之类的列表方法吗?
In Python, how big can a list get? I need a list of about 12000 elements. Will I still be able to run list methods such as sorting, etc?
推荐答案
According to the source code, the maximum size of a list is PY_SSIZE_T_MAX/sizeof(PyObject*)
.
PY_SSIZE_T_MAX
在 pyport.h 为((size_t) -1)>>1
在常规的32位系统上,这是(4294967295/2)/4或536870912.
On a regular 32bit system, this is (4294967295 / 2) / 4 or 536870912.
因此,在32位系统上,python列表的最大大小为 536,870,912 个元素.
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.
这篇关于Python列表可以有多大?的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!