Python列表的基础数据结构是什么? [英] What is the underlying data structure for Python lists?

查看:133
本文介绍了Python列表的基础数据结构是什么?的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

用于实现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屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆