Python列表的基础数据结构是什么? [英] What is the underlying data structure for Python lists?
问题描述
用于实现Python内置列表数据类型的典型底层数据结构是什么?
列表对象实现为
数组。它们针对快速
固定长度操作进行优化,并导致pop(0)和
insert(0,v)操作的O(n)
内存移动成本,这些操作更改
底层数据表示的大小和位置。
另请参见:
http://docs.python.org/library/collections.html#collections.deque
Btw,有趣的是Python数据结构教程建议使用pop(0)来模拟队列,但不提O(n)或deque选项。 / p>
http ://docs.python.org/tutorial/datastructures.html#using-lists-as-queues
What is the typical underlying data structure used to implement Python's built-in list data type?
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.
See also: http://docs.python.org/library/collections.html#collections.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屋!