Lists internally have some sort of capacity that changes depending on how many items we have in it. Is there such a way to access/read the capacity of python's list
?
Asked
Active
Viewed 766 times
1

Nether
- 1,081
- 10
- 14
-
2Why do you want to do this? – arshajii Dec 06 '16 at 16:44
-
So you wanna know the breaking point of a list in Python? Why? – Christian Dean Dec 06 '16 at 16:45
-
It's implementation specific. Some (old, possibly outdated) details of the CPython implementation are in a writeup here: http://www.laurentluce.com/posts/python-list-implementation/ – Patrick Haugh Dec 06 '16 at 16:49
-
I might be oversimplifying a bit, but do you mean the length of a given list or the maximum possible length of any list? – asongtoruin Dec 06 '16 at 16:50
-
1Possible duplicate of [How Big can a Python Array Get?](http://stackoverflow.com/questions/855191/how-big-can-a-python-array-get) – Chris_Rands Dec 06 '16 at 16:52
-
1@asongtoruin i think he means the physical memory allocated to a list at any one time. – Patrick Haugh Dec 06 '16 at 16:52
-
1You could try something like ``sys.getsizeof(theList) - sys.getsizeof([])``, although I'm not 100% sure of what that's measuring. – jasonharper Dec 06 '16 at 18:06
-
1I'm not familiar with Python, but in .NET, the `List` automatically increases its size when it exceeds its current internally-allocated capacity. I think the OP wants something like this https://msdn.microsoft.com/en-us/library/y52x03h2(v=vs.110).aspx – ps2goat Dec 06 '16 at 21:21
-
This is exactly what I'm looking for. As to why - I want to see when it resizes itself and other fun stuff – Nether Dec 07 '16 at 08:29