Python 列表可以有多大? [英] How Big can a Python List Get?

查看:36
本文介绍了Python 列表可以有多大?的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

在 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?

推荐答案

根据源代码,一个列表的最大大小为PY_SSIZE_T_MAX/sizeof(PyObject*).

According to the source code, the maximum size of a list is PY_SSIZE_T_MAX/sizeof(PyObject*).

PY_SSIZE_T_MAXpyport.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屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆