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

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

问题描述

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

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