python - Why is the time complexity of getting the length of a python list constant?
问题描述
This Python wiki says the time complexity of getting the length of a list is constant, or O(1):
lst = [4, 5, 6, 7]
len(lst)
# 4
However, I would expect it to be linear, or O(n), because all of the items in the list need to be counted. Is the length cached by the list? If not, how is the time complexity constant?
解决方案
推荐阅读
- r - roxygen 如何在函数参数中处理 ...
- reactjs - AppBar Material UI 问题
- php - 使用 JQuery 从同一个 Wordpress 插件目录中查找 PHP 文件,以便以编程方式加载它
- reactjs - styled-component 生成自定义 css 类
- python-3.x - 魔术函数 %matplotlib inline 的使用
- java - 重复的局部变量 x
- ruby-on-rails - 参数数量错误(给定 2,预期 1)
- azure - 如何找到我的 Microsoft Azure 媒体服务帐户名称?
- r - 如何在按下某个键之前暂停代码执行?
- wordpress - 在特定类别的帖子内容中查找和替换单词