Python 列表的底层数据结构是什么? [英] What is the underlying data structure for Python lists?
问题描述
用于实现 Python 内置列表数据类型的典型底层数据结构是什么?
What is the typical underlying data structure used to implement Python's built-in list data type?
推荐答案
列表对象实现为数组.它们针对快速进行了优化定长操作并产生 O(n)pop(0) 和insert(0, v) 改变的操作的大小和位置底层数据表示.
List objects are implemented as arrays. They are optimized for fast fixed-length operations and incur O(n) memory movement costs for pop(0) and insert(0, v) operations which change both the size and position of the underlying data representation.
另见:http://docs.python.org/library/collections.html#collections.deque
顺便说一句,我觉得有趣的是,Python 数据结构教程推荐使用 pop(0) 来模拟队列,但没有提到 O(n) 或 deque 选项.
Btw, I find it interesting that the Python tutorial on data structures recommends using pop(0) to simulate a queue but does not mention O(n) or the deque option.
http://docs.python.org/tutorial/datastructures.html#using-lists-as-queues
这篇关于Python 列表的底层数据结构是什么?的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!