Python的名单是如何实现的? [英] How is Python's List Implemented?

查看:147
本文介绍了Python的名单是如何实现的?的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

它是一个链表,一个数组?我搜索周围,只发现人的猜测。我的C知识是不够好,看看源$ C ​​$ C。

Is it a linked list, an array? I searched around and only found people guessing. My C knowledge isn't good enough to look at the source code.

推荐答案

这是一个数组。实践证明:索引需要(当然有非常小的差异(0.0013微秒)!),同时考虑指数:

It's an array. Practical proof: Indexing takes (of course with extremely small differences (0.0013 µsecs!)) the same time regardless of index:

...>python -m timeit --setup="x = [None]*1000" "x[500]"
10000000 loops, best of 3: 0.0579 usec per loop

...>python -m timeit --setup="x = [None]*1000" "x[0]"
10000000 loops, best of 3: 0.0566 usec per loop

我会很惊讶,如果IronPython的或Jython的使用链表 - 他们会毁建立在假设名单是数组许多许多广泛使用的库的性能。

I would be astounded if IronPython or Jython used linked lists - they would ruin the performance of many many widely-used libraries built on the assumption that lists are arrays.

这篇关于Python的名单是如何实现的?的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

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