Mike Cooper
Mike Cooper

Reputation: 3038

How does Python store lists internally?

How are lists in python stored internally? Is it an array? A linked list? Something else?

Or does the interpreter guess at the right structure for each instance based on length, etc.

If the question is implementation dependent, what about the classic CPython?

Upvotes: 18

Views: 6446

Answers (1)

sunqiang
sunqiang

Reputation: 6492

from Core Python Containers: Under the Hood
List Implementation:
Fixed-length array of pointers
* When the array grows or shrinks, calls realloc() and, if necessary, copies all of the items to the new space
source code: Include/listobject.h and Objects/listobject.c
btw: here is the video

Upvotes: 32

Related Questions