简体   繁体   中英

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?

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

The technical post webpages of this site follow the CC BY-SA 4.0 protocol. If you need to reprint, please indicate the site URL or the original address.Any question please contact:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM