How Big can a Python Array Get?

2019-01-01 01:01发布

In Python, how big can an array/list get? I need an array of about 12000 elements. Will I still be able to run array/list methods such as sorting, etc?

10条回答
情到深处是孤独
2楼-- · 2019-01-01 01:17

It varies for different systems (depends on RAM). The easiest way to find out is

import six six.MAXSIZE 9223372036854775807 This gives the max size of list and dict too ,as per the documentation

查看更多
步步皆殇っ
3楼-- · 2019-01-01 01:23

I'd say you're only limited by the total amount of RAM available. Obviously the larger the array the longer operations on it will take.

查看更多
查无此人
4楼-- · 2019-01-01 01:26

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.

查看更多
笑指拈花
5楼-- · 2019-01-01 01:27

In casual code I've created lists with millions of elements. I believe that Python's implementation of lists are only bound by the amount of memory on your system.

In addition, the list methods / functions should continue to work despite the size of the list.

If you care about performance, it might be worthwhile to look into a library such as NumPy.

查看更多
登录 后发表回答