python - list、tuple、dict底层数据结构

标签 python data-structures dictionary set tuples

<分区>

我想对 python 中的数据类型(list、tuple、dict 和 set)的实现方式有一些了解

它们是如何实现的,重要的是使用的数据结构。 有什么地方/网址可以准确地获得这种理解?

最佳答案

最好看的地方是 CPython implementation source code :

  • dict - 以快速解析键为目标的 HashMap
  • list - 看起来像一组 PyObject
  • tuple - 与列表相同,但具有元组允许的优化(固定大小,对象)
  • set - 具有缓存位置优化的 HashMap

源代码有大量注释并且写得很好 C。这将是了解详细使用的数据结构的最佳位置。

关于python - list、tuple、dict底层数据结构,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/21873755/

相关文章:

python - Django 可重用应用程序教程,ImportError : No module named 'polls'

javascript - 尝试为类似 RxJS 的结构开发 "pull mode"会出现 RangeError

Java内存不足错误: Strange behavior

javascript - 如何在javascript中实现字典?

python - 上传大文件 nginx + uwsgi

python - TensorFlow 中相当于 PyTorch 中的 expand() 的函数是什么?

python - 如何找到最接近给定值的值并返回相应的键

ios - 循环字典数组中的元素

python - 如何从 hadoop python 包装器运行 C++ 可执行文件

algorithm - 使用动态规划的最低成本